Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: daniellogin on July 08, 2018, 01:59:20 PM

Title: Pooling objects with FSM's : no resetting issue
Post by: daniellogin on July 08, 2018, 01:59:20 PM
Shortcut to question: How do you properly pool objects which have FSM's and other settings which need to reboot when they spawn?

In my project I have targets that are to be shot. As they detect collision with the projectile they disable the starting mesh renderer and enable broken parts which burst out. The FSM in the target objects also add to int values for score and telling the game to replace them, etc.

I set this up just plain creating the target objects using a prefab, but I noticed a little bit of hitching when the replacement items were spawning. So I pooled the targets and spawned them like that.

The problem is that the items are now spawning in their already broken state. They are saving all alterations, such as the starting mesh renderer disabled and the broken parts already enabled (and already blasted out with their add force actions).

Is there a way to renew the pooled objects when they are returned to the pool? Come to think of it, that sounds like it defeats the purpose of pooling them because it means you are in fact loading again...
Title: Re: Pooling objects with FSM's : no resetting issue
Post by: Fat Pug Studio on July 08, 2018, 03:51:46 PM
It's not an issue, it works that way.

You have to set variables defining the object manually again. I had the same problem, i recommend the first or last state to be resetting variables, so whenever you spawn something it gets default variables data.
Title: Re: Pooling objects with FSM's : no resetting issue
Post by: djaydino on July 08, 2018, 05:31:56 PM
Hi.
Indeed that's what i do also,
On start, Set all the 'Default Values'

It would actually be nice to have a check box like the 'Reset On Disable' but then for the variables.

I will do a feature request for it.
Title: Re: Pooling objects with FSM's : no resetting issue
Post by: djaydino on July 08, 2018, 05:36:37 PM
Hi,

I have made a request, you can  +1 it so there is a bigger chance it will be implemented.

Here is the thread : http://hutonggames.com/playmakerforum/index.php?topic=19062.0
Title: Re: Pooling objects with FSM's : no resetting issue
Post by: daniellogin on July 09, 2018, 10:32:07 AM
I don't think that's possible. Sure I could turn on the 'primary' (unbroken bottle) mesh renderer again and disable the parts, but each of the parts have their own fsm to blow them up. I can't un-explode the parts which flew off with their own physics (and also deleted themselves to not have thousands of rigid body objects permanently falling through the floor even just existing in general.

Thanks for replies anyway.
Title: Re: Pooling objects with FSM's : no resetting issue
Post by: Fat Pug Studio on July 10, 2018, 08:58:20 AM
Then pool the number of objects you'll be using and don't exceed it. You will increase loading time, but you will not have that issue.
Title: Re: Pooling objects with FSM's : no resetting issue
Post by: daniellogin on July 13, 2018, 03:38:17 AM
Then pool the number of objects you'll be using and don't exceed it. You will increase loading time, but you will not have that issue.
At first this sounded like a good idea, although with more thought it will still come back to the same problem... unless I pool literally 1 million objects or something.

See my game will have the player shooting targets. I could presume that 1 object per second for each of the targets would be enough in the timed game play, but what about the next timed period... and the one after that. Ultimately I will still be likely to run out of pooled items unless I prep a crazy large amount.

It would still come back to the fact that I would need to reset the objects pooled at some point.
Title: Re: Pooling objects with FSM's : no resetting issue
Post by: daniellogin on July 13, 2018, 03:43:35 AM
Hm actually, I would be resetting the pool. The pool would renew every time I loop back to the action where the pool command is, right?

Ok this sounds like the right idea again.
Title: Re: Pooling objects with FSM's : no resetting issue
Post by: Fat Pug Studio on July 13, 2018, 07:52:19 AM
If you can't unexplode the parts and want to use pooling, i recommend you reconsider the logic you're using to be able to support pooling.

As for running out of pooled items, if your game is divided into levels, you can use the time between levels (or something else which is appropriate) to remove all the items from the pool and replace them with fresh prefabs.