Retrieving spawner id then referencing memory returns null



  • I store the spawner ids my units come from in memory for reference later with something similar to:

    unit.memory.spawnID = Game.spawns[x].id //It's going through a loop

    Then later I go ahead and reference that with

    var recalledSpawner = Game.getObjectById(unit.memory.spawnID);

    This works great but for some reason if I try to get memory afterwards with:

    recalledSpawner.memory == null

    returns true, why is this? Can I fix in some way?


  • Culture

    Is Memory.spawns.recalledSpawnerName defined?
    That's the built in location where the memory attribute of a spawner points to


  • Culture

    Well first make sure that unit.memory.spawnID is actually the spawner's ID number.
    Next see if recalledSpawner is really a spawner (just console.log(recalledSpawner) ) if it doesn't say [spawner .....] then something's not right
    Lastly even if you have the spawn it doesn't mean Memory.spawns.Spawn1 is actually set to something, it might actually be set to null.



  • Wish I could edit my previous posts.

    Thanks for everyone that helped. The issue was due to a bad recalledSpawner reference. Issue is resolved.