Any tips for object pooling?

NodeCanvas Forums General Discussion Any tips for object pooling?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16263
    ccfoo242
    Participant

    I just read about the AsyncLoad option. Any other tips for implementing object pooling?

    When set to AsyncLoad, Graph Owner is not initialized if it is not ‘activeInHierarchy’ (useful for pooling).

     

     

    #16281
    Gavalakis
    Keymaster

    Hello there,

    AsyncLoad option itself is very good to instantiate / initialize graph owner objects even without pooling sometimes since most initialization is happening on a separate thread.

    As for typical pooling, you can pre-instantiate all your graph owner objects at the start of the game/scene so that they all initialize at that time. Remember to set the “On Enable” parameter on the graph owner inspector to “Do Nothing” so that the graph owner does not “Start Behaviour” automatically. Then when the time comes that you need that pre-instantiated graph owner, you can simply call owner.StartBehaviour() from code.

    The relationship between AsyncLoad, activeInHierarchy, and pooling, is because some people prefer to instantiate the graph owner objects (with AsyncLoad enabled ) and immediately deactivate them instead. Then activate them when they are needed in the game. This will result in the same thing as above, but I recommend using the first way described above instead.

    Let me know if this helps.

    Thanks.

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

    #16288
    ccfoo242
    Participant

    Thanks for the tips! When I tried to use the async option it failed miserably, but I assume that is because I’m not waiting for the background thread to finish. Do you have an example that shows how to use this option?

    And to be clear, with the way you suggest to implement pooling, I don’t actually need to use asyncload? I am pre-creating about 100 objects so I figured async would help speed up that initial step.

    #16302
    Gavalakis
    Keymaster

    Hello again and sorry for the late reply.

    Async Load would still help like you said to help in the initial step.

    With Async Load, the graph might take a few frames to be initialized since this happens on a separate thread. So it is best not to use the GraphOwner object immediately after you instantiate it. There is also a boolean -> ‘GraphOwner.initialized that you can use to check if the graph is initialized (thus AsyncLoad finished). There is no even for that currently, but I can add one if that helps.

    Let me know. Thanks!

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

    #16306
    ccfoo242
    Participant

    Thanks. I will try checking initialized. An event would definitely be helpful. But for now I can just poll initialized.

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