# User Data (Unit)

Grammar — User Data (userType, instance, field, index)
FlagsNative | Function

Returns a value from user data for the given type, instance, and field. User data is defined in the Data module.

# Arguments

  • string<gamelink::User> — User Type
  • string<userinstance> — Instance
  • string<userfield> — Field
  • int — Index

Returns — string<gamelink::Unit>

native string UserDataGetUnit(
	string inType,
	string inInstance,
	string inField,
	int inIndex,
);

Category: User Data / Get Value

# Examples

campaigns/swarmstory.sc2campaignbase.sc2data/TriggerLibs/SwarmCampaignLib.galaxy:7928

        lv_techUnit = libSwaC_gf_ZS_TechUnitOfArmyUnit(lv_purchasedArmyUnit);
    }
    return UserDataGetUnit("TechUnit", lv_techUnit, "UIUnitType", 1);
}

campaigns/swarmstory.sc2campaignbase.sc2data/TriggerLibs/SwarmCampaignLib.galaxy:7942

    if ((libSwaC_gf_ZS_StoryArmyCategoryState(lp_armyCategory) == c_armyCategoryStateLocked)) {
        lv_techUnit = libSwaC_gf_ZS_TechUnitOfArmyCategory(lp_armyCategory);
        return UserDataGetUnit("TechUnit", lv_techUnit, "UIEggType", 1);
    }

campaigns/swarmstory.sc2campaignbase.sc2data/TriggerLibs/SwarmCampaignLib.galaxy:7952

        lv_techUnit = libSwaC_gf_ZS_TechUnitOfArmyUnit(lv_purchasedArmyUnit);
    }
    return UserDataGetUnit("TechUnit", lv_techUnit, "UIUnitType", 1);
}

campaigns/swarmstory.sc2campaignbase.sc2data/TriggerLibs/SwarmCampaignLib.galaxy:8926

        lv_armyUnit = libSwaC_gf_StoryArmyUnitInCategory(libSwaC_gv_zS_ArmyCustomEvolutionCategory, 1);
        lv_techUnit = libSwaC_gf_ZS_TechUnitOfArmyUnit(lv_armyUnit);
        lv_unitType = UserDataGetUnit("TechUnit", lv_techUnit, "UIUnitType", 1);
        lv_offset = libSwaC_gf_ZS_ArmyCustomEvolutionUIUnitAttachment(lv_armyUnit);
        UnitCreate(1, lv_unitType, c_unitCreateIgnorePlacement, 0, lv_offset, PointGetFacing(lv_offset));

campaigns/swarmstory.sc2campaignbase.sc2data/TriggerLibs/SwarmCampaignLib.galaxy:8951

        lv_armyUnit = libSwaC_gf_StoryArmyUnitInCategory(libSwaC_gv_zS_ArmyCustomEvolutionCategory, 2);
        lv_techUnit = libSwaC_gf_ZS_TechUnitOfArmyUnit(lv_armyUnit);
        lv_unitType = UserDataGetUnit("TechUnit", lv_techUnit, "UIUnitType", 1);
        lv_offset = libSwaC_gf_ZS_ArmyCustomEvolutionUIUnitAttachment(lv_armyUnit);
        UnitCreate(1, lv_unitType, c_unitCreateIgnorePlacement, 0, lv_offset, PointGetFacing(lv_offset));

campaigns/swarmstoryutil.sc2modbase.sc2data/Lib281DEC45.galaxy:5030

        for ( ; auto9B2BC715_u <= UnitGroupCount(auto9B2BC715_g, c_unitCountAll) ; auto9B2BC715_u += BoolToInt(lv_indexUnit == UnitGroupUnit(auto9B2BC715_g, auto9B2BC715_u)) ) {
            lv_indexUnit = UnitGroupUnit(auto9B2BC715_g, auto9B2BC715_u);
            if ((UnitGetType(lv_indexUnit) == UserDataGetUnit("CalloutAttachment", lib281DEC45_gf_ZSS_CharacterCalloutData(lp_character), "Attach Unit", 1))) {
                DialogCreate(400, 400, c_anchorCenter, 0, 0, true);
                DialogSetImageVisible(DialogLastCreated(), false);

campaigns/voidstory.sc2campaignbase.sc2data/TriggerLibs/VoidCampaignLib.galaxy:1993

    // Automatic Variable Declarations
    // Implementation
    return UserDataGetUnit("Locations", libVoiC_gf_PC_LocationUserData(lp_location), "Unit", 1);
}

mods/heroesmapmods/battlegroundmapmods/braxisholdout.stormmodbase.stormdata/LibSCHO.galaxy:1581

        lv_itSpawnUnit = 1;
        for ( ; ( (auto2149D197_ai >= 0 && lv_itSpawnUnit <= auto2149D197_ae) || (auto2149D197_ai < 0 && lv_itSpawnUnit >= auto2149D197_ae) ) ; lv_itSpawnUnit += auto2149D197_ai ) {
            libNtve_gf_CreateUnitsWithDefaultFacing(1, UserDataGetUnit("BeaconWaves", lv_tier, lv_wave, lv_itUserData), 0, lv_owner, RegionRandomPoint(lp_spawnRegion), null);
            UnitGroupAdd(libSCHO_gv_mMHO_AttackGroups[lp_attackLane][libSCHO_gv_mMHO_WaveTracker], UnitLastCreated());
            UnitXPAddXP(UnitLastCreated(), null, libSCHO_gv_mMHO_ScalingLevel);

mods/missionpacks/campaigncommon.sc2modbase.sc2data/LibComC.galaxy:479

string libComC_gf_CC_LocationUnit (string lp_location) {
    // Implementation
    return UserDataGetUnit("Locations", libComC_gf_CC_LocationUserData(lp_location), "Unit", 1);
}

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

    }
    else {
        lv_aIPlayerRace = (CatalogFieldValueGet(c_gameCatalogUnit, UserDataGetUnit("CoopAICommanderTiers", UserDataGetUserInstance("CoopAICommanders", libCOMI_gv_cM_CoopAIPlayer_CommanderShared, "UnitTiers", 1), "PhaseUnits", 1), "Race", lp_player));
    }
    PlayerSetRace(lp_player, lv_aIPlayerRace);

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

    lv_unitTypeIter = 1;
    for ( ; ( (auto45C59D69_ai >= 0 && lv_unitTypeIter <= auto45C59D69_ae) || (auto45C59D69_ai < 0 && lv_unitTypeIter >= auto45C59D69_ae) ) ; lv_unitTypeIter += auto45C59D69_ai ) {
        lv_unitTypeTest = UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnits", lv_unitTypeIter);
        if ((lv_unitTypeTest != null)) {
            lv_unitTypeTestAlternate = UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternate", lv_unitTypeIter);

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

        lv_unitTypeTest = UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnits", lv_unitTypeIter);
        if ((lv_unitTypeTest != null)) {
            lv_unitTypeTestAlternate = UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternate", lv_unitTypeIter);
            if ((lv_unitTypeTestAlternate != null) && (RandomFixed(0.0, 1.0) < UserDataGetFixed("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternateChance", lv_unitTierIter))) {
                lv_unitTypeTest = lv_unitTypeTestAlternate;

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

                    lv_unitTypeLimitIter = 1;
                    for ( ; ( (auto90F247F5_ai >= 0 && lv_unitTypeLimitIter <= auto90F247F5_ae) || (auto90F247F5_ai < 0 && lv_unitTypeLimitIter >= auto90F247F5_ae) ) ; lv_unitTypeLimitIter += auto90F247F5_ai ) {
                        if ((lv_unitTypesForWave[lv_indexUnitType] == UserDataGetUnit("CoopAIAttackWaveUnitLimits", UserDataInstance("CoopAIAttackWaveUnitLimits", lv_unitTypeLimitIter), "UnitToLimit", 1))) {
                            if ((lv_unitTypePerWaveLimit[lv_indexUnitType] == lv_c_unitTypePerWaveLimit_Max)) {
                                lv_unitTypePerWaveLimit[lv_indexUnitType] = UserDataGetInt("CoopAIAttackWaveUnitLimits", UserDataInstance("CoopAIAttackWaveUnitLimits", lv_unitTypeLimitIter), "LimitPerDifficulty", lv_difficultyAsInt);

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

    lv_unitTypeIter = 1;
    for ( ; ( (autoA609CF0B_ai >= 0 && lv_unitTypeIter <= autoA609CF0B_ae) || (autoA609CF0B_ai < 0 && lv_unitTypeIter >= autoA609CF0B_ae) ) ; lv_unitTypeIter += autoA609CF0B_ai ) {
        lv_unitTypeTest = UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnits", lv_unitTypeIter);
        if ((lv_unitTypeTest != null) && (lv_difficultyAsInt >= UserDataGetInt("CoopAICommanderTiers", lv_commanderTier, "minDifficulty", lv_unitTypeIter))) {
            lv_unitTypesForWave[lv_indexUnitType] = lv_unitTypeTest;

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

            lv_unitTypePercentBase[lv_indexUnitType] = UserDataGetFixed("CoopAICommanderTiers", lv_commanderTier, "PercentOfWaveBase", lv_unitTypeIter);
            lv_unitTypePercentRandom[lv_indexUnitType] = (UserDataGetFixed("CoopAICommanderTiers", lv_commanderTier, "PercentOfWaveRandom", lv_unitTypeIter) + lv_unitTypePercentRandom[(lv_indexUnitType - 1)]);
            if ((UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternate", lv_unitTypeIter) != null) && (UserDataGetFixed("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternateChance", lv_unitTypeIter) != 0.0)) {
                if ((RandomFixed(0.0, 1.0) < UserDataGetFixed("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternateChance", lv_unitTierIter))) {
                    lv_unitType = UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternate", lv_unitTierIter);

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

            if ((UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternate", lv_unitTypeIter) != null) && (UserDataGetFixed("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternateChance", lv_unitTypeIter) != 0.0)) {
                if ((RandomFixed(0.0, 1.0) < UserDataGetFixed("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternateChance", lv_unitTierIter))) {
                    lv_unitType = UserDataGetUnit("CoopAICommanderTiers", lv_commanderTier, "PhaseUnitsAlternate", lv_unitTierIter);
                    lv_unitTypesForWave[lv_indexUnitType] = lv_unitType;
                }

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

            lv_unitTypeLimitIter = 1;
            for ( ; ( (autoE4FCA90D_ai >= 0 && lv_unitTypeLimitIter <= autoE4FCA90D_ae) || (autoE4FCA90D_ai < 0 && lv_unitTypeLimitIter >= autoE4FCA90D_ae) ) ; lv_unitTypeLimitIter += autoE4FCA90D_ai ) {
                if ((lv_unitTypesForWave[lv_indexUnitType] == UserDataGetUnit("CoopAIAttackWaveUnitLimits", UserDataInstance("CoopAIAttackWaveUnitLimits", lv_unitTypeLimitIter), "UnitToLimit", 1))) {
                    lv_unitTypePerWaveLimit[lv_indexUnitType] = UserDataGetInt("CoopAIAttackWaveUnitLimits", UserDataInstance("CoopAIAttackWaveUnitLimits", lv_unitTypeLimitIter), "LimitPerDifficulty", lv_difficultyAsInt);
                    break;

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

    lv_startingTechStockIter = 1;
    for ( ; ( (auto47D233A5_ai >= 0 && lv_startingTechStockIter <= auto47D233A5_ae) || (auto47D233A5_ai < 0 && lv_startingTechStockIter >= auto47D233A5_ae) ) ; lv_startingTechStockIter += auto47D233A5_ai ) {
        lv_startingTechStockUnit = UserDataGetUnit("CoopAICommanders", libCOMI_gv_cM_CoopAIPlayer_Commander[lp_player], "StartingTech", lv_startingTechStockIter);
        if ((lv_startingTechStockUnit != null)) {
            AISetStock(lp_player, UserDataGetInt("CoopAICommanders", libCOMI_gv_cM_CoopAIPlayer_Commander[lp_player], "StartingTechCount", lv_startingTechStockIter), lv_startingTechStockUnit);

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

    lv_unitCreateIter = 1;
    for ( ; ( (autoBC0EE9F6_ai >= 0 && lv_unitCreateIter <= autoBC0EE9F6_ae) || (autoBC0EE9F6_ai < 0 && lv_unitCreateIter >= autoBC0EE9F6_ae) ) ; lv_unitCreateIter += autoBC0EE9F6_ai ) {
        lv_unitToCreate = UserDataGetUnit("CoopAICommanders", libCOMI_gv_cM_CoopAIPlayer_Commander[lp_player], "StartingTech", lv_unitCreateIter);
        if ((lv_unitToCreate == null)) {
            continue;

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:776

        lv_type = 1;
        for ( ; ( (autoF2A2351D_ai >= 0 && lv_type <= autoF2A2351D_ae) || (autoF2A2351D_ai < 0 && lv_type >= autoF2A2351D_ae) ) ; lv_type += autoF2A2351D_ai ) {
            lv_killingUnitTestUnit = UserDataGetUnit("EvolutionTiers", lv_killerTier, "UnitsToEvolveInto", lv_type);
            if ((lv_killingUnitTestUnit == UnitGetType(lp_killingUnit))) {
                lv_killerSupply = lv_tier;

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:818

        lv_tierEndpoint = 8;
        for ( ; ( (auto10349771_ai >= 0 && lv_tierEndpoint <= auto10349771_ae) || (auto10349771_ai < 0 && lv_tierEndpoint >= auto10349771_ae) ) ; lv_tierEndpoint += auto10349771_ai ) {
            lv_endpointTestUnit = UserDataGetUnit("EvolutionTiers", UserDataInstance("EvolutionTiers", lv_tier), "UnitsToEvolveInto", lv_tierEndpoint);
            if ((lv_endpointTestUnit != "")) {
                break;

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:824


        }
        lv_newUnitType = UserDataGetUnit("EvolutionTiers", UserDataInstance("EvolutionTiers", lv_tier), "UnitsToEvolveInto", RandomInt(1, lv_tierEndpoint));
        if ((lv_newUnitType != "")) {
            break;

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:3465

            lv_tierEndpoint = 8;
            for ( ; ( (auto88F3D2BC_ai >= 0 && lv_tierEndpoint <= auto88F3D2BC_ae) || (auto88F3D2BC_ai < 0 && lv_tierEndpoint >= auto88F3D2BC_ae) ) ; lv_tierEndpoint += auto88F3D2BC_ai ) {
                lv_endpointTestUnit = UserDataGetUnit("EvolutionTiers", UserDataInstance("EvolutionTiers", lv_tier), "UnitsToEvolveInto", lv_tierEndpoint);
                if ((lv_endpointTestUnit != "")) {
                    break;

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOMU.galaxy:3471


            }
            lv_newUnitType = UserDataGetUnit("EvolutionTiers", UserDataInstance("EvolutionTiers", lv_tier), "UnitsToEvolveInto", RandomInt(1, lv_tierEndpoint));
            if ((lv_newUnitType != "")) {
                break;

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOOC.galaxy:1091

    lv_index = 1;
    for ( ; ( (autoA8942F1B_ai >= 0 && lv_index <= autoA8942F1B_ae) || (autoA8942F1B_ai < 0 && lv_index >= autoA8942F1B_ae) ) ; lv_index += autoA8942F1B_ai ) {
        TechTreeUnitAllow(lp_player, UserDataGetUnit("PlayerPrestige", lp_prestige, "DisableUnit", lv_index), false);
    }
    autoAF2781D7_ae = UserDataFieldValueCount("PlayerPrestige", "UpgradeSupplements");

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOUI.galaxy:5387

    lv_replaceTargetTop = (libCOUI_gv_cM_Tychus_SharedAbil_ButtonBase + lv_abilIndex + "Top");
    lv_replacePlayer = UnitGetOwner(libCOMI_gf_EventTychusHero());
    lv_structureGroup = UnitGroup(UserDataGetUnit("CoopTechTychusSquad", lp_squadInstance, "EquipmentStructure", 1), UnitGetOwner(lp_unit), RegionEntireMap(), UnitFilter(0, 0, (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0);

    // Implementation

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOUI.galaxy:5471

    for ( ; autoA8D2E402_i <= UserDataInstanceCount(autoA8D2E402_userType) ; autoA8D2E402_i += 1 ) {
        lv_instance = UserDataInstance(autoA8D2E402_userType, autoA8D2E402_i);
        if ((UnitGetType(lp_unit) == UserDataGetUnit("CoopTechTychusSquad", lv_instance, "Unit Type", 1))) {
            return lv_instance;
        }

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOUI.galaxy:8936

        lv_squadinstance = UserDataInstance(auto008A9DF3_userType, auto008A9DF3_i);
        lv_squadindex = UserDataGetInt("CoopTechTychusSquad", lv_squadinstance, "Squad Slot", 1);
        if ((libNtve_gf_TriggeringProgressUnitType() == UserDataGetUnit("CoopTechTychusSquad", lv_squadinstance, "Unit Type", 1)) && (lv_squadindex >= 0)) {
            libNtve_gf_SetDialogItemCurrentValue(libCOUI_gv_cU_TychusSquadTrainingProgressBar, 100.0, PlayerGroupAll());
            DialogControlSetAnimationState(libCOUI_gv_cU_TychusSquadUnitFrames[lv_squadindex], PlayerGroupAll(), "TrainingState", "Training");

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOUI.galaxy:8984

        lv_squadinstance = UserDataInstance(auto349501FD_userType, auto349501FD_i);
        lv_squadindex = UserDataGetInt("CoopTechTychusSquad", lv_squadinstance, "Squad Slot", 1);
        if ((libNtve_gf_TriggeringProgressUnitType() == UserDataGetUnit("CoopTechTychusSquad", lv_squadinstance, "Unit Type", 1)) && (lv_squadindex >= 0)) {
            DialogControlSetAnimationState(libCOUI_gv_cU_TychusSquadUnitFrames[lv_squadindex], PlayerGroupAll(), "TrainingState", "NotTraining");
            break;

mods/starcoop/starcoop.sc2modbase.sc2data/LibCOUI.galaxy:9097

        lv_squadinstance = UserDataInstance(autoAFAE43F4_userType, autoAFAE43F4_i);
        lv_squadindex = UserDataGetInt("CoopTechTychusSquad", lv_squadinstance, "Squad Slot", 1);
        if ((lv_squadindex != -1) && (UnitGetType(libCOMI_gf_EventTychusStructure()) == UserDataGetUnit("CoopTechTychusSquad", lv_squadinstance, "EquipmentStructure", 1))) {
            libNtve_gf_SetDialogItemUnit(libCOUI_gv_cU_TychusSquadEquipmentStructureTargets[lv_squadindex], libCOMI_gf_EventTychusStructure(), PlayerGroupAll());
        }

mods/warcoop/warcoopdata.sc2modbase.sc2data/TriggerLibs/WarCoopData.galaxy:587

    // Implementation
    if ((libWCdr_gf_PlayerIsLegendPlayer(lp_legendPlayer) == true)) {
        return UserDataGetUnit("PlayableLegends", libWCdr_gf_GetLegendInstanceForPlayer(lp_legendPlayer), "HeroUnit", 1);
    }
    else {

mods/warcoop/warcoopdata.sc2modbase.sc2data/TriggerLibs/WarCoopData.galaxy:2717

    lv_waveunitindex = 1;
    for ( ; ( (auto7AF0E6AE_ai >= 0 && lv_waveunitindex <= auto7AF0E6AE_ae) || (auto7AF0E6AE_ai < 0 && lv_waveunitindex >= auto7AF0E6AE_ae) ) ; lv_waveunitindex += auto7AF0E6AE_ai ) {
        lv_waveunittype = UserDataGetUnit("LegionWaves", lp_wave, "UnitTypes", lv_waveunitindex);
        lv_waveunitweight = UserDataGetInt("LegionWaves", lp_wave, "UnitWeights", lv_waveunitindex);
        if ((lv_waveunittype != null) && (lv_waveunittype != "") && (lv_waveunitweight > 0) && ((libWCdr_gf_GetCostofUnitInWave(lp_wave, lv_waveunitindex) >= 0) && (libWCdr_gf_GetCostofUnitInWave(lp_wave, lv_waveunitindex) <= (lp_budget * 2)))) {

mods/warcoop/warcoopdata.sc2modbase.sc2data/TriggerLibs/WarCoopData.galaxy:2728

    lv_waveunitindex = 1;
    for ( ; ( (auto73BD3D6C_ai >= 0 && lv_waveunitindex <= auto73BD3D6C_ae) || (auto73BD3D6C_ai < 0 && lv_waveunitindex >= auto73BD3D6C_ae) ) ; lv_waveunitindex += auto73BD3D6C_ai ) {
        lv_waveunittype = UserDataGetUnit("LegionWaves", lp_wave, "UnitTypes", lv_waveunitindex);
        lv_waveunitweight = UserDataGetInt("LegionWaves", lp_wave, "UnitWeights", lv_waveunitindex);
        if ((lv_waveunittype != null) && (lv_waveunittype != "") && (lv_waveunitweight > 0) && ((libWCdr_gf_GetCostofUnitInWave(lp_wave, lv_waveunitindex) >= 0) && (libWCdr_gf_GetCostofUnitInWave(lp_wave, lv_waveunitindex) <= (lp_budget * 2)))) {

mods/warcoop/warcoopdata.sc2modbase.sc2data/TriggerLibs/WarCoopData.galaxy:2791

    // Automatic Variable Declarations
    // Variable Initialization
    lv_unittype = UserDataGetUnit("LegionWaves", lp_wave, "UnitTypes", lp_unitIndex);
    lv_overridevalue = UserDataGetInt("LegionWaves", lp_wave, "UnitValueOverrides", lp_unitIndex);
    lv_xpvalue = CatalogFieldValueGetAsInt(c_gameCatalogUnit, lv_unittype, "KillXP", c_playerAny);