edited August 2015 in ORK Scripting
I'm using CombatantSpawner component added in runtime to spawn random enemy combatant groups in defined positions. Depending on some internal settings i'm adding some amount of CombatantSpawner components to different GameObjects, then i'm set up them - combatant groups, spawnRandom, battleType, Arena, unique spawnerId and so on.
In current test case i have 5 CombatantGroups added to every CombatantSpawner component;
And, now what i have in result:
- Not every spawner actually spawns combatants, spawned amount is nearly random - from 8 Spawners only 0-4 combatant groups actually spawned.
- Only first group from 5 CombatantGroups is spawned, never saw other groups.

Here is actual code:
var spawnObject = spawner.AddComponent<CombatantSpawner>();
spawnObject.useNearestArena = true;
spawnObject.battleType = BattleSystemType.TurnBased;
spawnObject.arenaRange = 100000f;
spawnObject.spawnRandom = true;
spawnObject.autoStartAfter = 1f;
spawnObject.startType = EventStartType.Autostart;
spawnObject.combatant = new BattleCombatant[MobGroups.Count];
for (int combatantIndex = 0; combatantIndex < MobGroups.Count; combatantIndex++) {
var battleCombatant = new BattleCombatant {
factionID = 1,
useGroup = true,
id = MobGroups[combatantIndex].RealID
spawnObject.combatant[combatantIndex] = battleCombatant;
spawnObject.spawnerID = Guid.NewGuid().ToString();
Post edited by PoDM on
  • The spawnerID is only used for remembering the spawned combatants and respawn times when leaving the scene.

    Your spawners aren't all spawning, because by default the scene ID will be used - once it's set, other spawners with the same ID will not spawn (and by default, the ID is 0 if you add them via script).
    You should either set a unique scene ID, or disable using the scene ID, e.g.:
    spawnObject.useSceneID = false;

    Generally, I'd not advise doing that by code. It's better to use prefabs with already set up spawners for that.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • I see, thank you.
    I'll try to use prefabs instead of scripts.
Sign In or Register to comment.