playMaker

Author Topic: Pooling 'dynamic' objects which change  (Read 868 times)

daniellogin

  • Full Member
  • ***
  • Posts: 215
Pooling 'dynamic' objects which change
« on: October 05, 2019, 02:09:20 AM »
OK so I have an 'advanced' question about pooling. What I mean is not just the 'how to' or basic 'why', but what to do when you have to consider a specific situation.

I have a set of 3 bridges in a mini game, where 1 is randomly selected each round to break when you are mid way across. The bridge is made from a dozen or so basic Unity boxes as planks. Each piece has a rigid body (starting kinematic) and the bridge collapses when a an event is received (by sending to all children of their parent object).

So back to pooling; I want to spawn each bridge at the start of the round, so I can then randomly choose when one to send an event to so it will know it's chosen to collapse. If I spawn from a pool though, I'm going to end up spawning a broken bridge eventually. It will keep all of the child objects local positions and rotations, etc.

What should I do though? Do I go through the hassle of one by one making each object start with an FSM which manually sets their local position and rotation, plus turn their rigid body back to kinematic? Or do I just Create Object and not worry about the overhead?

To make it a bit more specific; this is a mini game in a bigger game. I don't know how many times it will be played during a game session. It will be one of several (ideally there will be a dozen or more mini games) that are randomly selected at random times. This is relevant because I'm trying to say you won't necessarily be doing the game over and over (so more and more overhead), but maybe I guess it could play 2 or even 3 times? I don't know.

This is a PC game, but I'm already going pretty hard on the 3d rendering, so a entry level 'gaming pc' is already needed at minimum.

Any thoughts?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Pooling 'dynamic' objects which change
« Reply #1 on: October 17, 2019, 05:20:28 AM »
Hi,

pooling is meant to be so that you don't create objects, so no, you should not just create the objects again and again, as it defeats the purpose.

 instead, yes reset the positions of everything when you are either putting back the object in the pool or when you you take one from the pool. that's do not matter much.

I would not go with one fsm per planks, but maybe one fsm at the top that serialize all positions into cache and you implement a reset event that goes over each objects and put them back into place and set up the rigidbody properly.

you can use arraymaker for storing the cache.

Or you implement some hack where each object default position is 0,0,0, and reseting simply means putting everything back to 0,0,0. maybe that's possible in your case.

Bye,

 Jean