playMaker

Author Topic: Pooler - Simple Pooling System.  (Read 2170 times)

ergin

  • Junior Playmaker
  • **
  • Posts: 86
    • View Profile
Pooler - Simple Pooling System.
« on: June 06, 2016, 07:31:50 AM »
Hello, I wrote a simple pooling system for my project and wanted to share with community.

Use "Pooler Pool" Action to pool any number of objects you need. Then by using "Pooler Spawn" you can enable objects instead of instantiating them during the game. By using "Pooler Destroy" you can disable pooled objects so that you can re-use them when neccesary. Pooler pool has the ability to grow the pool if neccesary but it's optional.

https://github.com/ergin3d/PlayMakerCustomActions_U5/tree/master/Assets/PlayMaker-Custom-Actions/Pooler

This is my first upload to ecosystem, so I'm unsure if I uploaded to right place or followed the right steps.

Also for the coding I can't say I am an expert coder. I hope some pros here can check the code. ;)

Thanks.

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #1 on: June 06, 2016, 08:34:28 AM »
Hi,

Thx a lot...

Question:
i have used another pool manager and on each spawn, i had to manually by send event restart my fsm.. So spawn (fsm works on start, depawn, spawn (send event to get the fsm to work).
With yours, when spwan then despawn then spawn, does it start the fsm or will i have to manually activate the fsm?

ergin

  • Junior Playmaker
  • **
  • Posts: 86
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #2 on: June 06, 2016, 09:41:37 AM »
Hello and Thanks!

I hope I didn't misunderstand the question.

When I pool, then spawn, then despawn(destroy) and spawn again, object is disabled and then re-enabled. By default when an object with FSM is disabled then re-enabled it starts from the begining "start" event. So there is no need to send any event.

Edit: Spelling
« Last Edit: June 06, 2016, 11:27:44 AM by ergin »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #3 on: June 06, 2016, 10:09:18 AM »
Cool thx... I will try it in my next project..  :)

KellyRay

  • Full Member
  • ***
  • Posts: 169
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #4 on: June 06, 2016, 12:44:04 PM »
Thanks Ergin! Will check this out

PlaymakerNOOB

  • Full Member
  • ***
  • Posts: 117
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #5 on: June 29, 2016, 08:17:03 PM »
I am using this pooling system and it seems great... until I restart the scene.  Then I am getting the following errors in console log.  Unity 5.3

--start of console log--
Pooler: Same pool exists, choose unique names for pools
UnityEngine.Debug:Log(Object)
HutongGames.PlayMaker.Actions.PoolerPool:PoolObjects() (at Assets/Custom Playmaker/Pooling System/PoolerPool.cs:145)
HutongGames.PlayMaker.Actions.PoolerPool:OnEnter() (at Assets/Custom Playmaker/Pooling System/PoolerPool.cs:59)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:200)
HutongGames.PlayMaker.FsmState:OnEnter() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:168)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2155)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2113)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2041)
HutongGames.PlayMaker.Fsm:UpdateState(FsmState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2171)
HutongGames.PlayMaker.Fsm:Update() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1425)
PlayMakerFSM:Update() (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:435)

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
--End of console log--

ergin

  • Junior Playmaker
  • **
  • Posts: 86
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #6 on: June 30, 2016, 01:59:34 AM »
Hello,

as for the first line of debug you have different pools with same name. Can you please try to find if there are different pooled objects with same pool name? Also a pool should only be initialized only once. You may be attempting to initialize the same pool twice.

As for the ---"MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object."---

My script doesn't destroy objects but disables them I don't think pooler generates this log. Is this a test scene? if it is can you please send it to me?

ergin@sitailetisim.com

Thanks.

PlaymakerNOOB

  • Full Member
  • ***
  • Posts: 117
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #7 on: June 30, 2016, 03:33:28 PM »
thanks, i've sent you an email with my box link for download.

I've deleted pretty much everything except whats necessary to create a basic version.

ergin

  • Junior Playmaker
  • **
  • Posts: 86
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #8 on: June 30, 2016, 10:50:49 PM »
Thanks. I fixed the problem. Actually it was my fault. I'm using this action in my project I never needed to restart a scene in my game.

When a scene is reloaded, object arrays where spawned instances are stored do not reset but all the spawned objects are deleted because of a reload. I solved it by adding an awake() function which executes when a scene is loaded and resets arrays.

You can download new version:
https://github.com/ergin3d/PlayMakerCustomActions_U5/blob/master/Assets/PlayMaker-Custom-Actions/Pooler/PoolerPool.cs

Thanks again.

PlaymakerNOOB

  • Full Member
  • ***
  • Posts: 117
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #9 on: July 01, 2016, 03:51:04 AM »
thanks, it works!

ergin

  • Junior Playmaker
  • **
  • Posts: 86
    • View Profile
Re: Pooler - Simple Pooling System.
« Reply #10 on: July 01, 2016, 11:33:04 AM »
you're welcome...  :)