playMaker

Author Topic: Spawn/De Spawn with PoolManager  (Read 1178 times)

jackel

  • Playmaker Newbie
  • *
  • Posts: 6
Spawn/De Spawn with PoolManager
« on: December 27, 2020, 08:22:31 AM »
Hello and Merry Christmas, after many searches here and other places I've came back to ask again for help for my project. It's an endless vertical game, and I want to despawn the objects left behind the camera. I'm using PoolManager actions but I'm in a deadlock, I can't figure out how to use the despawn action. So for the moment I have a SpawnGameObject which will spawn first 10 obstacles, then will stop and wait. Everything works fine, I'm not sure if it's ok what I've made, because it's spawning random obstacles from prefabs stored in a variable. The same prefabs are declared in the SpawnPool. But now I don't know where to put the despawn action, and how to make it work, I've tried with a simple destroy self action when triggered.
So my logic is something like that:
De Spawn action should despawn when player trigger box enter in the prefab trigger area, but the problem is I want to de spawn last obstacle which is a random one. So i can't tell De Spawn what Game Object should despawn. If I put the variable it will try to despawn a random one, and will throw an error. So I'm thinking I should make states for every obstacle and check them all and if It's one it will be despawned. I think it could be an easy way and I can't figure it out.

Ok and the second problem is with the loop spawning, after 10 obstacles spawner stops, i've tried to re-compare ints after destroying some obstacles, but it won't start to spawn again.
If somebody can help me some hints it will be great, or a scheme with the states. Sorry for this long post and lots of infos without pics. If you need to see my FSM i will post some screenshots.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7621
    • jinxtergames
Re: Spawn/De Spawn with PoolManager
« Reply #1 on: December 27, 2020, 09:56:12 AM »
Hi.
I use Leanpool but logic should work similar.

For this case :
Have a trigger behind the camera (to detect if a object is behind the camera)

Have a fsm with a trigger on the pooled object.
The this will look for the trigger behind the camera.
when trigger do despawn action.

For 2nd, there might be some settings for pools that stops pooling if a maximum is reached.


jackel

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Spawn/De Spawn with PoolManager
« Reply #2 on: December 27, 2020, 10:37:23 AM »
Yes that's what I use too, a trigger behind the camera and on on the prefab object. But my despawn action needs: Pool Name, Game Object, etc. If I set the Game Object: main game object that holds the prefabs it won't work. Because I can't de spawn by tag, I think I'll need to make a FSM with 8 checks for every object in part.

For the 2nd, I've used Int add, Int Compare(to set maximum at 10), Set Vector 3 for position, and create game object(in my case Pmt Spawn). After the maximum is reached it will stop, now I must figure it out how to make it spawn again after one by one for every despawn, to maintain the maximum amount. Because in my first tests I let the game spawn without limit and the game crashed because I had over 50000 parts created in 30 seconds. So I need to make it have 10 active obstacles for a better optimization.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Spawn/De Spawn with PoolManager
« Reply #3 on: December 27, 2020, 02:25:52 PM »
You put the Despawn Action on the pooled prefab.

So it's despawning itself.

jackel

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Spawn/De Spawn with PoolManager
« Reply #4 on: December 27, 2020, 04:49:03 PM »
Thanks:)) this was the problem, I had a De Spawn action in the prefabs, but it was a wrong Game Object, after you told me this. I've checked again, repair the error, and now it works.

Now I must figure how to add one by one the despawned prefabs. It will be a long night.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Spawn/De Spawn with PoolManager
« Reply #5 on: December 29, 2020, 01:55:12 AM »
In the same State as the Despawn, immediately before the Despawn action you can have a Send Event, that triggers another Spawn.

On your Prefab (of the thing being spawned), in the same FSM as your Despawn action, at the Start state, add a 'Find Game Object' and enter the name of the Object that is controlling your Pool Boss Spawn. This will create an Object variable.

Back in your main project hierarchy, on the object that has the Pool Boss Spawn, create a Global Event that links to the State with the Pool Boss Spawn.

Back on your Prefab, immediately before the Pool Boss Despawn, use a Send Event to send a signal to the Global Event that spawns a new Prefab.

On the Send Event, choose Game Object FSM, Specify Game Object, and here enter the object variable name that you created in the Find Game Object in your Start state.

In the Send Event, enter the global event you created back in your Pool Boss Spawn FSM.



Make sense?

jackel

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Spawn/De Spawn with PoolManager
« Reply #6 on: December 30, 2020, 07:55:43 PM »
Thanks, totally makes sense now, something like that I've tried to make too. But now I realised how lazy I am and I've recreated the game logic, made two chunks to start the game and one prefab chunk for late game. So now at the middle of the chunk I've put a trigger to spawn the next chunk, and at the end of the chunk a despawner. Thank you again for your time.