playMaker

Author Topic: CreateObject - Performance hit[SOLVED]  (Read 3432 times)

Justin

  • Junior Playmaker
  • **
  • Posts: 58
CreateObject - Performance hit[SOLVED]
« on: January 06, 2013, 03:18:04 PM »
     I have noticed while play testing a game I have been working on I get a noticable hiccup in performance every time I create an object using the create object action in my FSMs.  I'm trying to design a game where many objects get created and deleted on the fly.  The objects are prefabs sometimes a single bullet to an entire level chunk which consists of many objects parented to an empty object.  I am getting this performance hiccup every time an object is created no matter the size or amount.  The objects get created through FSM triggers and input functions.  I am wondering if there is something I can do to fix this? I am using the free version of Unity, but I have bought the cheap $400 iOs license, I am planning on play testing it on a device when I have a chance to update my Xcode to see if the build version performs differently.

     I realize I have probably not provided enough information to get an accurate answer.  I am unsure of what details to provide to better pinpoint my problem; as I am rather new to this game designing business and have only been teaching myself the ends and outs through tutorials and such over the past few months.  Thanks in advance to anyone who might help.
« Last Edit: January 07, 2013, 03:04:58 AM by jeanfabre »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: CreateObject - Performance hit
« Reply #1 on: January 06, 2013, 04:07:56 PM »
The usual strategy is to create object pools at level start and re-use (enable/disable) objects while the level is running. So you pay the cost up front when loading the level.

There are third party object pool managers on the asset store supported by custom Playmaker actions here.

I'm sure others can jump in with their experience too....

Justin

  • Junior Playmaker
  • **
  • Posts: 58
Re: CreateObject - Performance hit
« Reply #2 on: January 06, 2013, 04:15:58 PM »
Thank you for the quick reply, I figured it would be something I am naive to.  I will start researching object pools and how to implement them.

Horror

  • Junior Playmaker
  • **
  • Posts: 79
Re: CreateObject - Performance hit[SOLVED]
« Reply #3 on: January 07, 2013, 05:02:09 AM »
I was initially creating enemies on the fly with CreateObject. You do get a lot of stuttering when you do it this way. I switched to PoolManager - problem solved!

It's easy to implement, especially with the custom playMaker actions. You set up an object in your scene with a PoolManager component, then specify which prefabs you want pre-loaded in the pool. Then you can pretty much spawn your prefabs like you would with CreateObject, only without the performance hit.

The most difficult thing I found is that you need to manually reset your prefab's behaviours before respawning it. Because the prefab is being recycled rather than destroyed and recreated, it will be added back into the scene in the state it was in before despawning.

So if you did something like disabling a collider, you would have to make sure to turn it back on yourself.

Justin

  • Junior Playmaker
  • **
  • Posts: 58
Re: CreateObject - Performance hit[SOLVED]
« Reply #4 on: January 07, 2013, 08:29:39 PM »
Thank you horror for your pointers, I had just purchased pool manager yesterday night after comparing it with two others it seems to be the obvious choice. I haven't had a chance to mess with it yet, but I'll keep what you said in mind when I do.  I don't think I'll have to change too much on my recycled objects as most of them have no scripts or have a looping behaviour except for maybe the coins and power ups, so that is good to know.  Thanks again.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: CreateObject - Performance hit[SOLVED]
« Reply #5 on: January 10, 2013, 05:23:36 AM »
Hi,

 yes, and don't forget than pool Manager 2 has a set of custom action for playmaker:

https://hutonggames.fogbugz.com/default.asp?W839

bye,

 Jean