playMaker

Author Topic: Arraymaker & Spawning Prefabs  (Read 3811 times)

Budde88

  • Full Member
  • ***
  • Posts: 165
Arraymaker & Spawning Prefabs
« on: May 03, 2016, 05:41:43 AM »
I have created a basic setup to spawn Prefabs for my game using Arraymaker,
my question is this...

Looking at my setup, is this an efficient way of creating gameobjects for mobile?
and, does my current system recycle the Prefabs so that when they are created again and again, they are not loaded into the scene each time.

Thanks

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Arraymaker & Spawning Prefabs
« Reply #1 on: May 03, 2016, 10:51:53 AM »
If you are using "Create Object" I don't believe that is a traditional pooling setup- you would instead use "activate object" instead of create- from my understanding pooling solutions create all the objects at runtime- then activate/deactivate them as needed as its the "create" and destroy actions that cause CPU spikes-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Arraymaker & Spawning Prefabs
« Reply #2 on: May 03, 2016, 11:06:40 AM »
Thanks for the reply,

I wasn't sure if I had done it correctly, I'm going to try as you suggested.
Just hope it's as simple as the setup I already have.

Thanks again

If anyone has anything else to add, please chip in.

Need a solid 60fps

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Arraymaker & Spawning Prefabs
« Reply #3 on: May 03, 2016, 11:16:49 AM »
Also have you checked out PoolManager? https://www.assetstore.unity3d.com/en/#!/content/1010 its time tested and solid and has all the playmaker actions you need for it-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Arraymaker & Spawning Prefabs
« Reply #4 on: May 03, 2016, 11:32:25 AM »
I haven't checked any of them out, trying to go the cheaper route ;)

One quick question, If I am trying to pool Prefabs, how do I go about using the Activate/De-activate method?

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Arraymaker & Spawning Prefabs
« Reply #5 on: May 03, 2016, 11:48:17 AM »
There's some posts on this forum about creating a pooling solution with Arraymaker- I've never tried to roll my own but I assume you could use "activate game object" and use the enable toggle to activate/deactivate objects
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Arraymaker & Spawning Prefabs
« Reply #6 on: May 03, 2016, 01:04:34 PM »
I cannot find an example here on the forums :(

I just can't understand how you could use the Activate/De-activate option for a Prefab, that's why I'm creating objects instead, even though it's probably wrong lol.

Can someone please shed some light here and post an example pertaining to my screenshots above.

Thanks

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Arraymaker & Spawning Prefabs
« Reply #7 on: May 03, 2016, 01:15:40 PM »
What Poolmanager does is add clones of your object to be pooled to the scene and deactivates them at runtime- then when you want to "spawn" one it activates it-

So you prob would create X number of objects at runtime- add them to an array, deactivate them- then use array actions to activate/deactivate them as needed-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

ransomink

  • Playmaker Newbie
  • *
  • Posts: 44
Re: Arraymaker & Spawning Prefabs
« Reply #8 on: May 04, 2016, 02:05:15 AM »
There are a few ways this can be done. The idea is to create all your objects at once (during runtime) and deactivate them for later use. You'll need to create another array to add all your cloned prefabs in, ie. I have an array called Currency where all of my cloned coins are added to.

As you already have:
-use Array List Get Next to retrieve the next gameobject
-then Create Object to create the gameobject
-then Activate Game Object to deactivate the gameobject
-and Add the gameobject to an array list (the one you created to hold all your clones).

The FINISHED event for the last state (the one adding the gameobject to the array) should connect back to the state that uses Array List Get Next so it can continue until all items have been created...

Budde88

  • Full Member
  • ***
  • Posts: 165
Re: Arraymaker & Spawning Prefabs
« Reply #9 on: May 04, 2016, 04:32:32 AM »
This seems to be a better solution than what I had planned, will let you know how it goes when I get around to doing it.

If I get it working I may just set up an example for everyone to see in the future.

Thanks

ransomink

  • Playmaker Newbie
  • *
  • Posts: 44
Re: Arraymaker & Spawning Prefabs
« Reply #10 on: May 04, 2016, 06:40:18 AM »
No problem. Let me know if you get it to work; I tested it and use it myself.

NOTE: This is only setting up your gameobjects in a pool. You will need to setup how to spawn and activate/deactivate them when needed...