Global BB variable not being updated

NodeCanvas Forums Support Global BB variable not being updated

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9441
    karmelov
    Participant

    Hello,

    Im using a pooling system to manage all my NPCs.
    I create a persistent pool with all the creatures, and their FSMs.

    I also have a global BB that stores information, like a reference to the player. Since the player and the global BB are not persistent between scenes, when a new scene loads, a new global BB is created loading the new player reference.

    The issue is when I have a creature spawn and use the player reference from the global BB, it works perfectly. But when I change scene, and a creature that was already pooled in another scene tries to use the player reference from the global BB, I get a “MissingReferenceException: The object of type ‘GameObject’ has been destroyed but you are still trying to access it.” error.

    I think this is caused because the FSM loads the player reference from the global BB once, and when the scene changes, it tries to load the reference from the old and obsolete global BB.

    Is there a way to force the FSM to reload the global references? Or am I doing something wrong? Should I use another approach?

    Thanks,

    #9444
    Gavalakis
    Keymaster

    Hey,

    Global Blackboards are persistant between scenes (DontDestroyOnLoad) by default. If your player is also persistant, the reference to it would not be lost, but if the player is not, then yes, you would need to assign the reference at the start of the scene.

    The FSM, does not cache the refence in any way, so it should read the the new value of the “player” variable on the Global BB.
    Is the player reference on the Gloabal BB correctly assigned and not null or missing when the error is thrown?

    Please let me know.
    Thanks

    Join us on Discord: https://discord.gg/97q2Rjh

    #9443
    karmelov
    Participant

    Hello,

    The player is not persistant between scenes, but the NPCs are.

    The player reference in the global BB is correct, since when a new scene is loaded, NPCs that were never pooled work correctly, getting the player reference correcly. Only NPCs that were pooled in another scene get the incorrect reference of the player.

    NPCs only retrieve the player reference correctly when they are first spawned in the same scene (an NPC can spawn all the times we want correctly in the same scene), but when we change scene, if the NPC already spawned in a previous scene, we get the reference error.

    Thanks,

    #9442
    Gavalakis
    Keymaster

    Hey,

    Sorry for the late reply.
    Can you please provide more info on when you get the error? Is it caused by some NodeCanvas action/condition?
    Alternatively can you post the stack trace?

    Thanks!

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.