# Replace Unit

Grammar — Replace unit with a unitType using options|Replace Unit Options vitals
FlagsAction

Use “Last Replaced Unit” to refer to the replacement unit. Note that any variables referring to the old unit will need to be updated.

# Arguments

  • unit — Unit
  • string<gamelink::Unit> — Unit-Type
  • int<preset::ReplaceUnitOptions> — Options

Returns — void

void libNtve_gf_ReplaceUnit(
	unit lp_unit,
	string lp_unitType,
	int lp_options,
);

Category: Unit / Basic

# Examples

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/evolution/zevolutionhydralisk.sc2map/MapScript.galaxy:1229

    while (!UnitGroupLoopDone()) {
        if ((UnitGetType(UnitGroupLoopCurrent()) == "HydraliskBurrowed")) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Hydralisk", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphHydraliskToHydraliskImpaler", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/evolution/zevolutionmutalisk.sc2map/MapScript.galaxy:960

            UnitGroupAdd(gv_mutaliskGroup, EventUnit());
            if ((TriggerIsEnabled(gt_ObjectiveCollectBroodLordEssenceComplete) == false)) {
                libNtve_gf_ReplaceUnit(EventUnit(), "MutaliskBroodlord", libNtve_ge_ReplaceUnitOptions_NewUnitssMax);
                UnitGroupAdd(gv_mutaliskGroup, libNtve_gf_LastReplacedUnit());
            }

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/evolution/zevolutionmutalisk.sc2map/MapScript.galaxy:4208

    UnitGroupLoopBegin(UnitGroup("MutaliskViper", gv_pLAYER_01_USER, RegionFromId(6), UnitFilter(0, 0, (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0));
    for ( ; !UnitGroupLoopDone() ; UnitGroupLoopStep() ) {
        libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Viper", libNtve_ge_ReplaceUnitOptions_NewUnitssMax);
        UnitGroupAdd(gv_viperGroup, libNtve_gf_LastReplacedUnit());
    }

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/evolution/zevolutionroach.sc2map/MapScript.galaxy:1084

    while (!UnitGroupLoopDone()) {
        if ((UnitGetType(UnitGroupLoopCurrent()) == "RoachBurrowed")) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Roach", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphRoachToCorpser", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/evolution/zevolutionswarmhost.sc2map/MapScript.galaxy:878

    while (!UnitGroupLoopDone()) {
        if (((UnitGetType(UnitGroupLoopCurrent()) == "SwarmHostRooted") || (UnitGetType(UnitGroupLoopCurrent()) == "SwarmHostBurrowed"))) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "SwarmHost", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphSwarmHostToSplitA", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/evolution/zevolutionswarmhost.sc2map/MapScript.galaxy:1623

    while (!UnitGroupLoopDone()) {
        if (((UnitGetType(UnitGroupLoopCurrent()) == "SwarmHostRooted") || (UnitGetType(UnitGroupLoopCurrent()) == "SwarmHostBurrowed"))) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "SwarmHost", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphSwarmHostToSplitB", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/evolution/zevolutionultralisk.sc2map/MapScript.galaxy:1310

    while (!UnitGroupLoopDone()) {
        if ((UnitGetType(UnitGroupLoopCurrent()) == "UltraliskBurrowed")) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Ultralisk", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphUltraliskToNoxious", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/evolution/zevolutionultralisk.sc2map/MapScript.galaxy:2129

        libNtve_gf_SendActorMessageToUnit(UnitGroupLoopCurrent(), "ClearTintColor");
        if ((UnitGetType(UnitGroupLoopCurrent()) == "UltraliskBurrowed")) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Ultralisk", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphUltraliskToTorrasque", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/zchar01.sc2map/MapScript.galaxy:1347

            auto9CD86608_var = UnitGroupUnitFromEnd(auto9CD86608_g, auto9CD86608_u);
            if (auto9CD86608_var == null) { break; }
            libNtve_gf_ReplaceUnit(auto9CD86608_var, "InfestedTerranCampaign", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
        }
    }

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/swarm/zlab01.sc2map/MapScript.galaxy:10697

    UnitSetPosition(UnitFromId(114), PointFromId(461), false);
    UnitIssueOrder(UnitFromId(114), OrderTargetingUnit(AbilityCommand("attack", 0), UnitFromId(515)), c_orderQueueReplace);
    libNtve_gf_ReplaceUnit(gv_mainDoor, "UmojanLabDoorsThinRightLowered", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
    gv_mainDoor = libNtve_gf_LastReplacedUnit();
    UIAlertClear(gv_pLAYER_01_USER);

campaigns/swarm.sc2campaignbase.sc2maps/maps/campaign/voidprologue/voidprologue03.sc2map/MapScript.galaxy:8988

    libNtve_gf_PlayAnimation(libNtve_gf_MainActorofUnit(UnitFromId(283)), c_animNameDefault, "Stand Morph", c_animFlagPlayForever, c_animTimeDefault);
    TriggerStop(gt_IntroBridgeSequence);
    libNtve_gf_ReplaceUnit(UnitFromId(1020), "XelNaga_Caverns_Floating_BridgeH8", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
    CameraShakeStop(gv_pLAYER_01_USER);
    SoundtrackStop(PlayerGroupAll(), c_soundtrackCategoryMusic, true);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/evolution/zevolutionhydralisk.sc2mapMapScript.galaxy:1229

    while (!UnitGroupLoopDone()) {
        if ((UnitGetType(UnitGroupLoopCurrent()) == "HydraliskBurrowed")) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Hydralisk", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphHydraliskToHydraliskImpaler", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/evolution/zevolutionmutalisk.sc2mapMapScript.galaxy:960

            UnitGroupAdd(gv_mutaliskGroup, EventUnit());
            if ((TriggerIsEnabled(gt_ObjectiveCollectBroodLordEssenceComplete) == false)) {
                libNtve_gf_ReplaceUnit(EventUnit(), "MutaliskBroodlord", libNtve_ge_ReplaceUnitOptions_NewUnitssMax);
                UnitGroupAdd(gv_mutaliskGroup, libNtve_gf_LastReplacedUnit());
            }

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/evolution/zevolutionmutalisk.sc2mapMapScript.galaxy:4208

    UnitGroupLoopBegin(UnitGroup("MutaliskViper", gv_pLAYER_01_USER, RegionFromId(6), UnitFilter(0, 0, (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0));
    for ( ; !UnitGroupLoopDone() ; UnitGroupLoopStep() ) {
        libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Viper", libNtve_ge_ReplaceUnitOptions_NewUnitssMax);
        UnitGroupAdd(gv_viperGroup, libNtve_gf_LastReplacedUnit());
    }

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/evolution/zevolutionroach.sc2mapMapScript.galaxy:1084

    while (!UnitGroupLoopDone()) {
        if ((UnitGetType(UnitGroupLoopCurrent()) == "RoachBurrowed")) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Roach", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphRoachToCorpser", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/evolution/zevolutionswarmhost.sc2mapMapScript.galaxy:878

    while (!UnitGroupLoopDone()) {
        if (((UnitGetType(UnitGroupLoopCurrent()) == "SwarmHostRooted") || (UnitGetType(UnitGroupLoopCurrent()) == "SwarmHostBurrowed"))) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "SwarmHost", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphSwarmHostToSplitA", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/evolution/zevolutionswarmhost.sc2mapMapScript.galaxy:1623

    while (!UnitGroupLoopDone()) {
        if (((UnitGetType(UnitGroupLoopCurrent()) == "SwarmHostRooted") || (UnitGetType(UnitGroupLoopCurrent()) == "SwarmHostBurrowed"))) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "SwarmHost", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphSwarmHostToSplitB", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/evolution/zevolutionultralisk.sc2mapMapScript.galaxy:1310

    while (!UnitGroupLoopDone()) {
        if ((UnitGetType(UnitGroupLoopCurrent()) == "UltraliskBurrowed")) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Ultralisk", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphUltraliskToNoxious", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/evolution/zevolutionultralisk.sc2mapMapScript.galaxy:2129

        libNtve_gf_SendActorMessageToUnit(UnitGroupLoopCurrent(), "ClearTintColor");
        if ((UnitGetType(UnitGroupLoopCurrent()) == "UltraliskBurrowed")) {
            libNtve_gf_ReplaceUnit(UnitGroupLoopCurrent(), "Ultralisk", 1);
            libNtve_gf_MakeUnitUncommandable(libNtve_gf_LastReplacedUnit(), true);
            UnitIssueOrder(libNtve_gf_LastReplacedUnit(), Order(AbilityCommand("MorphUltraliskToTorrasque", 0)), c_orderQueueReplace);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zchar01.sc2mapMapScript.galaxy:1347

            auto9CD86608_var = UnitGroupUnitFromEnd(auto9CD86608_g, auto9CD86608_u);
            if (auto9CD86608_var == null) { break; }
            libNtve_gf_ReplaceUnit(auto9CD86608_var, "InfestedTerranCampaign", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
        }
    }

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/swarm/zlab01.sc2mapMapScript.galaxy:10697

    UnitSetPosition(UnitFromId(114), PointFromId(461), false);
    UnitIssueOrder(UnitFromId(114), OrderTargetingUnit(AbilityCommand("attack", 0), UnitFromId(515)), c_orderQueueReplace);
    libNtve_gf_ReplaceUnit(gv_mainDoor, "UmojanLabDoorsThinRightLowered", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
    gv_mainDoor = libNtve_gf_LastReplacedUnit();
    UIAlertClear(gv_pLAYER_01_USER);

campaigns/swarm.sc2campaign/base.sc2maps/maps/campaign/voidprologue/voidprologue03.sc2mapMapScript.galaxy:8988

    libNtve_gf_PlayAnimation(libNtve_gf_MainActorofUnit(UnitFromId(283)), c_animNameDefault, "Stand Morph", c_animFlagPlayForever, c_animTimeDefault);
    TriggerStop(gt_IntroBridgeSequence);
    libNtve_gf_ReplaceUnit(UnitFromId(1020), "XelNaga_Caverns_Floating_BridgeH8", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
    CameraShakeStop(gv_pLAYER_01_USER);
    SoundtrackStop(PlayerGroupAll(), c_soundtrackCategoryMusic, true);

campaigns/void.sc2campaignbase.sc2maps/maps/campaign/void/paiur05.sc2map/MapScript.galaxy:454

        autoDF7AB5E9_var = UnitGroupUnitFromEnd(autoDF7AB5E9_g, autoDF7AB5E9_u);
        if (autoDF7AB5E9_var == null) { break; }
        libNtve_gf_ReplaceUnit(autoDF7AB5E9_var, "InfestedTerranCampaign", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
    }
    return true;

campaigns/void.sc2campaignbase.sc2maps/maps/campaign/void/sc2epilogue02.sc2map/MapScript.galaxy:8217

    UISetFrameVisible(PlayerGroupAll(), c_syncFrameTypeSupply, true);
    PingDestroy(libHots_gf_PingStoredForUnit(gv_kERRIGAN, 1));
    libNtve_gf_ReplaceUnit(UnitFromId(1489), "BarracksTechReactor", libNtve_ge_ReplaceUnitOptions_NewUnitsDefault);
    autoED2C508D_g = UnitGroup(null, gv_pLAYER_02_DOMINION8, RegionPlayableMap(), UnitFilter(0, (1 << (c_targetFilterHidden - 32)), (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32))), 0);
    autoED2C508D_u = UnitGroupCount(autoED2C508D_g, c_unitCountAll);

campaigns/void.sc2campaignbase.sc2maps/maps/campaign/void/sc2epilogue02.sc2map/MapScript.galaxy:8228

        libNtve_gf_PauseUnit(autoED2C508D_var, false);
    }
    libNtve_gf_ReplaceUnit(UnitFromId(65), "SiegeTankSieged", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
    libLbty_gf_OrderWorkerstoGatherNearbyResources(RegionEntireMap(), gv_pLAYER_01_USER);
    UnitClearSelection(gv_pLAYER_01_USER);

campaigns/void.sc2campaign/base.sc2maps/maps/campaign/void/paiur05.sc2mapMapScript.galaxy:454

        autoDF7AB5E9_var = UnitGroupUnitFromEnd(autoDF7AB5E9_g, autoDF7AB5E9_u);
        if (autoDF7AB5E9_var == null) { break; }
        libNtve_gf_ReplaceUnit(autoDF7AB5E9_var, "InfestedTerranCampaign", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
    }
    return true;

campaigns/void.sc2campaign/base.sc2maps/maps/campaign/void/sc2epilogue02.sc2mapMapScript.galaxy:8217

    UISetFrameVisible(PlayerGroupAll(), c_syncFrameTypeSupply, true);
    PingDestroy(libHots_gf_PingStoredForUnit(gv_kERRIGAN, 1));
    libNtve_gf_ReplaceUnit(UnitFromId(1489), "BarracksTechReactor", libNtve_ge_ReplaceUnitOptions_NewUnitsDefault);
    autoED2C508D_g = UnitGroup(null, gv_pLAYER_02_DOMINION8, RegionPlayableMap(), UnitFilter(0, (1 << (c_targetFilterHidden - 32)), (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32))), 0);
    autoED2C508D_u = UnitGroupCount(autoED2C508D_g, c_unitCountAll);

campaigns/void.sc2campaign/base.sc2maps/maps/campaign/void/sc2epilogue02.sc2mapMapScript.galaxy:8228

        libNtve_gf_PauseUnit(autoED2C508D_var, false);
    }
    libNtve_gf_ReplaceUnit(UnitFromId(65), "SiegeTankSieged", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
    libLbty_gf_OrderWorkerstoGatherNearbyResources(RegionEntireMap(), gv_pLAYER_01_USER);
    UnitClearSelection(gv_pLAYER_01_USER);

mods/novastoryassets.sc2modbase2.sc2maps/maps/campaign/nova/nova05.sc2map/MapScript.galaxy:5471

    libNtve_gf_SendActorMessageToUnit(gv_terrazineTankLocations[gv_terrazineTankLocationsCount].lv_beaconUnit, "SetMinimapVisibility");
    if ((libLotv_gf_DifficultyValueInt2(0, 0, 0, 1) == 1)) {
        libNtve_gf_ReplaceUnit(gv_terrazineTankLocations[gv_terrazineTankLocationsCount].lv_terrazineTankUnit, "NovaTerrazineTankDead", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
        UnitRemove(gv_terrazineTankLocations[gv_terrazineTankLocationsCount].lv_beaconUnit);
        gv_terrazineTankLocations[gv_terrazineTankLocationsCount].lv_state = ge_PRESETTerrazineTankState_Sealed;

mods/novastoryassets.sc2mod/base2.sc2maps/maps/campaign/nova/nova05.sc2mapMapScript.galaxy:5471

    libNtve_gf_SendActorMessageToUnit(gv_terrazineTankLocations[gv_terrazineTankLocationsCount].lv_beaconUnit, "SetMinimapVisibility");
    if ((libLotv_gf_DifficultyValueInt2(0, 0, 0, 1) == 1)) {
        libNtve_gf_ReplaceUnit(gv_terrazineTankLocations[gv_terrazineTankLocationsCount].lv_terrazineTankUnit, "NovaTerrazineTankDead", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
        UnitRemove(gv_terrazineTankLocations[gv_terrazineTankLocationsCount].lv_beaconUnit);
        gv_terrazineTankLocations[gv_terrazineTankLocationsCount].lv_state = ge_PRESETTerrazineTankState_Sealed;

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMI.galaxy:26484

        auto8B4AE5B8_var = UnitGroupUnitFromEnd(auto8B4AE5B8_g, auto8B4AE5B8_u);
        if (auto8B4AE5B8_var == null) { break; }
        libNtve_gf_ReplaceUnit(auto8B4AE5B8_var, "TychusResearchCenterUnlocked", libNtve_ge_ReplaceUnitOptions_OldUnitsRelative);
        libNtve_gf_CopyUnitControlGroups(auto8B4AE5B8_var, libNtve_gf_LastReplacedUnit());
        UnitCreateEffectUnit(auto8B4AE5B8_var, "TychusResearchCenterCopyRally", libNtve_gf_LastReplacedUnit());