Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Nefertiti on December 08, 2015, 07:13:26 AM

Title: Spawn objects and make them move
Post by: Nefertiti on December 08, 2015, 07:13:26 AM
Hello,

I'm trying to make a 2D game in playmaker, no knowedge in coding.
I'll appreciate any help.

I already have a spawner which works fine spawning randomly colored random objects.But what I need is that each newly created object, let's say triangle, circle, square etc., moved to a certain target position and be destroyed reaching that point, which works fine if I have FSM with "move toward" and "destroy" actions inside a prefab.
But I feel that there should be some other way using a single managing GameObject ("Game Manager") and variables, because now I just copy/pasted FSM to 4 different prefabs, but what if I have 100 and I need to change speed or something, so I have to change it in all 100 prefabs. Doesn't sound right to me.

So in a spawner FSM I have "select random object" (store it in "random object" variable), "create object" (store GO in "current obect" variable), set material color to the "current object". So far with the Game Manager I managed to create 2 types of behavior and both are not what I need: 1)"current object" moves toward the target, when destroyed a new object is spawned 2)"current object" starts moving but as soon as new object is spawned it stops. Instead a newly spawned object moves until another object is spawned.

I'm sorry for the long description, I hope it's clear what I need to achieve. Is it possible to do that or I need to do all the movements and actions in the prefabs?

I tried to play around with arrays but could only achieve the same 2results as with Game Manager object.
I would be happy to get any help, clues, guesses as I'm struggling with it for few days already. Thank you
Title: Re: Spawn objects and make them move
Post by: KellyRay on December 08, 2015, 02:32:34 PM
If I understand you right, you want to spawn an object at random from a set group of prefabs? And you want that random object to also have and random properties? But you do not want to make 100 objects and set them in your group of prefabs?

I don't think you have to have all your logic in the same FSM. So, you would spawn the template prefab. The prefab would do its random stuff and set its own properties, and then tell itself to move and be destroyed. The only thing that spawning manager has to worry about is when to spawn the next object. It doesn't have to control the logic of the object that it spawned.
Title: Re: Spawn objects and make them move
Post by: Nefertiti on December 09, 2015, 04:57:19 AM
Thank you for your reply, KellyRay.

It works!Thank you so much.

Although I have another question regarding this new setup. So now I have a spawner that only creates this Template Prefab every 2 sec and the Template prefab in its turn selects another random prefab and also creates a new object, sets color etc. Probably the question sounds silly, but isn't it too many of "create object" actions. After a while there are about 10 Template Prefabs on the scene and other 10 objects created one by each Template Prefab. If I make all the move-destroy thing in each individual prefab there will be only 10 objects on the scene without another 10 Templates.
What I want to ask is which thing is right or more appropriate to do in terms of app work speed, I don't know how it's called in programming, more efficient probably, which one would take less RAM(or whatever it is taken when the app runs) on a mobile phone:
1) putting FSM with move-destroy states into each individual prefab that needs to be spawned (let's say I'm not lasy to make 100 objects with same FSM)
2) spawning Template Prefab that creates another object?

Thanks again for the reply
Title: Re: Spawn objects and make them move
Post by: KellyRay on December 09, 2015, 10:57:27 AM
Not a silly question at all.

You are right, creating and destroying a lot of objects is generally considered a bad practice in terms of performance. The best way to overcome this as it was described to me is a thing called Pooling objects.

Where you spawn all the objects you will need at the beginning of the scene and then turn them all off. Your Spawning FSM would just enable a random object rather than create it. And you would deactive and reset the position instead of destorying the object.

This is the asset that I use to do this: http://poolmanager.path-o-logical.com/
They have playmaker actions.

There are several free spawners as well. Though none come to mind that have playmaker actions.

One last thought. I said that creating and destroying objects were bad practice. This doesn't mean that it doesn't work. Don't get so wrapped up in potential performance problems until that it hinders you from trying to make game play. A problem is only a problem when it becomes one. If creating and destroying objects doesn't bog down your game, then keep going. It's not too hard to replace create object actions with spawn objects.
Title: Re: Spawn objects and make them move
Post by: Nefertiti on December 09, 2015, 11:48:36 AM
Thank you for your advice.

I'll move on with Template Prefab for now, so far it works fine, so I should probably do other things insteads of getting stuck on this one issue. Who knows probably in the end I'll have to change everything:)

Thanks again, you really helped me on this.
Title: Re: Spawn objects and make them move
Post by: KellyRay on December 14, 2015, 08:18:25 AM
My pleasure!

And you are right. At the end of this, you will have learned so much more that as you look back to where you started you will begin to rethink and find better more efficient and clean ways of doing things. But until then, I'd suggest be scrappy and dirty and tricky to make it all work. I've come to this realization that most games are like a swan on a lake. Sailing smooth as butter on the surface, but kicking like hell underneath.