playMaker

Author Topic: How to force spawner to reset Prefab to it's initial state?  (Read 1751 times)

Neikke

  • Full Member
  • ***
  • Posts: 134
Guys, please help! I'm using More Mountain's Infinite Runner engine. So here's the situation:

I have a spawner which spawns 1 out of 5 platforms in random order, and sends them towards my player character, one after another, simple as that.

On each of those prefab platforms I have Coins which I force to be activated from the start in FSM. Then Player collects Coins by colliding with them, sending add +1 to Coins manager and finally deactivating the coin. Also very simple.

Everything's working nice and correctly for some time, but after a while, my platforms start spawning with almost no coins, or only a few of them. As I understand it, it happens because at some point at runtime Unity starts to think that the Platform with No coins - is the Original one and continues to spawn it instead of the one with untouched Coins!

Did anyone experience anything like this? Forcing Activation of those coins didn't help. Platforms keep spawning already deactivated.

Any help or advice is much appreciated!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to force spawner to reset Prefab to it's initial state?
« Reply #1 on: June 05, 2019, 03:30:17 PM »
Hi.
I don't have 'More Mountain's Infinite Runner engine' so i am not sure how they pool things.

But normally if they get disabled and the fsm as well, on enabling again the fsm should restart from the 'start' transition(unless setting was changed on the fsm tab), BUT variables are not reset.

So what i do with something like this is :

On start state Disable all coins and set all variables to its default value i want it to be.

Next state Enable Random coins

But from what you have written i think you are already doing something like that.
So i think best is to find out if the fsm gets disabled or not.

GonerGames

  • Junior Playmaker
  • **
  • Posts: 53
Re: How to force spawner to reset Prefab to it's initial state?
« Reply #2 on: June 05, 2019, 07:55:03 PM »
MoreMountains creates a pool of your platform prefabs in the Spawn Manager. As you collect the coins from each spawned platform you are then deactivating the coins permanently using the Playmaker FSM. As the pool recycles the platforms it does not automatically turn the coins back on as it remembers that you have deactivated the coins.

To get around this:
Make a Empty Game Object "Coin Holder"
Drop your collectable coin into the Coin Holder as a child
On the Coin Holder make an FSM with:
   - State 1: Wait 0.1 -> go to state 2
   - State 2: Activate collectible coin object

Now when the platform reactivates the FSMs on the Coin holder will run and reactivate the collectible coins.

By also having the collectable coin as a child of the Coin Holder it is also easy to reset the position of the collectable coin if needed. Eg. Magnet power up that pulls the coins towards you therefore needing a reset of the coin position for next time.

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to force spawner to reset Prefab to it's initial state?
« Reply #3 on: June 06, 2019, 05:06:49 AM »
Hi.
I don't have 'More Mountain's Infinite Runner engine' so i am not sure how they pool things.

But normally if they get disabled and the fsm as well, on enabling again the fsm should restart from the 'start' transition(unless setting was changed on the fsm tab), BUT variables are not reset.

So what i do with something like this is :

On start state Disable all coins and set all variables to its default value i want it to be.

Next state Enable Random coins

But from what you have written i think you are already doing something like that.
So i think best is to find out if the fsm gets disabled or not.

Hi, the thing is I'm not deactivating FSMs, they're always there. And I even have Activate Game Object action in the Start node. Actually it's not only Coins I have troubles with, I experience the same problems with not going back to original state even on simplest animated objects. For example I have a few trees that have falling to the ground animation, and they work fine (resetting in the beginning) only for 4 or 5 spawn rounds, after that, all consequent platforms start spawning with fallen trees already..

MoreMountains creates a pool of your platform prefabs in the Spawn Manager. As you collect the coins from each spawned platform you are then deactivating the coins permanently using the Playmaker FSM. As the pool recycles the platforms it does not automatically turn the coins back on as it remembers that you have deactivated the coins.

To get around this:
Make a Empty Game Object "Coin Holder"
Drop your collectable coin into the Coin Holder as a child
On the Coin Holder make an FSM with:
   - State 1: Wait 0.1 -> go to state 2
   - State 2: Activate collectible coin object

Now when the platform reactivates the FSMs on the Coin holder will run and reactivate the collectible coins.

By also having the collectable coin as a child of the Coin Holder it is also easy to reset the position of the collectable coin if needed. Eg. Magnet power up that pulls the coins towards you therefore needing a reset of the coin position for next time.

This sounds interesting definitely, and though I do use parent gameobject similar to CoinHolder you mentioned, I have Activate Game Object action right in the beginning Start State node of its FSM. Can you please tell me why do you suggest putting Activate Game Object to the second state, and having to Wait  for 0.1 sec in the first Start node? Why not re-activating all "deactivated" objects directly in the Start node?

Thanks!

« Last Edit: June 06, 2019, 05:40:43 AM by Neikke »

GonerGames

  • Junior Playmaker
  • **
  • Posts: 53
Re: How to force spawner to reset Prefab to it's initial state?
« Reply #4 on: June 06, 2019, 08:01:20 AM »
I have the wait in there so that I know that the Activate Game Object will fire off correctly. If I put Activate Game Object in the first state then it didn't seem to work properly. Just a testing thing that worked for us.

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: How to force spawner to reset Prefab to it's initial state?
« Reply #5 on: June 06, 2019, 08:10:46 AM »
I have the wait in there so that I know that the Activate Game Object will fire off correctly. If I put Activate Game Object in the first state then it didn't seem to work properly. Just a testing thing that worked for us.

That's definitely worth giving a try. Thanks a lot!