playMaker

Author Topic: how does the prefab pooling work?  (Read 3003 times)

kiriri

  • Hero Member
  • *****
  • Posts: 506
how does the prefab pooling work?
« on: October 05, 2012, 12:41:40 PM »
Hi, I was just wondering how the prefab pooling works inside playMaker. I noticed it first today, because I have a prefab which creates a number of other prefabs, and if instantiated first, everything works great. However, when I use it again, it immediatly picks of where the other left of, same variables and all. It's not that big of a deal if one knows about it, so I was wondering whether someone here could share some light on the topic. Just briefly :)

Cheers,
kiriri
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how does the prefab pooling work?
« Reply #1 on: October 09, 2012, 02:54:22 AM »
hi,

 There is no pooling built in playmaker, I am not sure what you are doing here, can you elaborate?

bye,

 Jean

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: how does the prefab pooling work?
« Reply #2 on: October 09, 2012, 06:22:27 AM »
well I have 2 kind of inventory prefabs. One is a spawner, which is in essence a page of the inventory. Once instantiated, it spawns a lot of Item prefabs. It uses a loop to do so, which counts up to 64, waiting for .2 seconds after each newly spawned prefab so you can see it nice and clear how each item is created one after another, and since it's only planes it doesn't cause any performance issues even on a mobile device. Then it sets the parent of each child to the page GameObject.

Now that's all fine and dandy. But!.. when I press the button to create another page, and this button really does nothing more than instantiate the very same prefab, unity starts to lag for half a second or so and then the entire page + items is there, and not only did it jump all the wait actions, it's even identical with the previous page, each item has the same values (like weapons which I just picked up) and there's one additional inventory item because when the spawn FSM for the items starts, it first creates a new item, then checks if the total index of items is more or equal than 64. Since the Index was 64 to begin with, it creates a 65th item and only then notices that that's quite too much :D

So my conclusion: Even though I'm creating this new page from a prefab, it actually copies the already instantiated version of it.

It's not a pressing issue, but it's come up multiple times and I have to use an initializing state to reset every attribute on spawn of a prefab to avoid it, which is obviously bad for the performance.
« Last Edit: October 09, 2012, 06:25:42 AM by kiriri »
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how does the prefab pooling work?
« Reply #3 on: October 09, 2012, 07:41:15 AM »
Hi,

 It's likely a mix up in your fsm and what variable you use at the time, etc etc. Without any more information, it's going to be difficult to give advice, cause out of the blue I don't any reason why it would straight away lag on a call that performed fine a moment ago. Pm me if you want me to look at your project, maybe I'll find the issue.

bye,

 Jean

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: how does the prefab pooling work?
« Reply #4 on: October 09, 2012, 08:52:47 AM »
thanks jean, I'll send it to you once I finish the tutorial, which would be in a week or so. But you've already helped me a lot with just your comment right now. I looked it up, and the created object is indeed not the prefab, but the default version of it in the scene. Weird thing is, if I set it to prefab (it's absolute, no variables involved, just setting the value to the prefab in the action) it automatically switches back to the scene version when I hit play. I made all the changes on the prefab, so no idea how this can happen ... Ah no, while I wrote that just now I saw the problem : since the target object is the same as the prefab, it's interpreted not as a prefab, but as the owner, could that be it?
So instead of create "prefab" it uses create "owner", I think I had that a couple of times before. Thanks a lot for the mindpush ;)
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how does the prefab pooling work?
« Reply #5 on: October 09, 2012, 10:25:59 AM »
Make sure that if you drag a prefab into the scene manually, you actually edit the prefab itself, else playmaker variable will not commit back if you hit apply.

bye,

 Jean