Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: PaulH on May 18, 2014, 01:35:32 PM

Title: How to spawn a random object using pool manager/playmaker?
Post by: PaulH on May 18, 2014, 01:35:32 PM
hi all

so i built my game whereby i spawn random game objects at a random position using the playmaker action selectRandomGameObject, store that object in a variable and spawn that variable at a random position. All was well until i built to IOS and found doing it that way killed the fps, so i just went and bought pool manager5 now (well decided to buy the full package actually Pool, Target, Constrain Bundle), anyway after installing the playmaker actions i cannot figure out how to do this using pool manager/playmaker.

could there not be an equivalent pool manager action to the selectRandomGameObject standard playmaker action, selectRandomGameObjectFromPool with the option to store that object in a variable and spawn where you want later? and/or spawnRandomObjectFrompool action?

could any super-brain out there make one/them? i cant code (hence why im using playmaker). surely this action will come in handy to so many users?

hope i haven't just wasted my money :(

any help would be greatly appreciated

Thanks

Paul

edit: i found the attached actions on another thread The "PmtSpawnMany" is the random spawn action im looking for but they aren't working in their current state, can someone fix them please?

edit: fixed the above actions but they are not what i'm looking for. they just spawn multiple, not random.

Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: mweyna on May 19, 2014, 01:43:42 AM
You could build an FSM system that basically gets a list of all viable object types from one ArrayList, and then gets a random position from another Arraylist to spawn it to.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: PaulH on May 19, 2014, 10:11:30 AM
You could build an FSM system that basically gets a list of all viable object types from one ArrayList, and then gets a random position from another Arraylist to spawn it to.

hi. but how would that be accessing the objects from the pool?

Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: mweyna on May 19, 2014, 01:05:52 PM
You'd get the ArrayCount then pick a random position, say three, and get that object using the Array Get playmaker action.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: PaulH on May 19, 2014, 06:51:50 PM
sorry but i dont get you. the objects in the pool (instances of the prefabs) get created at runtime, so how do i get those objects in the pool into an array list? which action would do that?

sorry again but i am quite new to all this and i haven't really used arrays before, just learning as i go.

isnt it easy to edit the standard playmaker action 'select random object' and instead set it to select a random object from the pool?



Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: mweyna on May 20, 2014, 12:28:01 AM
The standard playmaker logic isn't fully aware of Arrays, because ArrayMaker is an add-on to the Playmaker tools. Thus, the need for special actions. Assuming you have the added ArrayMaker actions you could use "Array List Get Random" to find a random object.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: PaulH on May 20, 2014, 06:43:43 AM
The standard playmaker logic isn't fully aware of Arrays, because ArrayMaker is an add-on to the Playmaker tools. Thus, the need for special actions. Assuming you have the added ArrayMaker actions you could use "Array List Get Random" to find a random object.

hi. your idea sounds perfect and yes i have arraymaker actions installed, 'but' how do i get the instances that are created at runtime (in the pool, using poolmanager) 'into' an array list to then use ArrayListGetRandom?

once i figure that part im good to go.  :)

thanks again for your help.

Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: mweyna on May 20, 2014, 11:49:30 AM
How are you spawning the objects now? In your FSM where you have your spawner that creates the item in a pool, couldn't you just have it add that object to an Array upon creation? With my project, I do just that and it maintains accurate arrays without issue.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: Rafe on May 23, 2014, 11:27:08 AM
...so i built my game whereby i spawn random game objects at a random position using the playmaker action selectRandomGameObject, store that object in a variable and spawn that variable at a random position.

Hi,

I was just pointed to this thread. I wrote PoolManager but haven't had the oppertunity to use PlayMaker yet. I know someone from PlayMaker is reading this thread, so hopefully they can help translate my point

If your setup was already working with Instantiate before adding PoolManager, It should still work. PoolManager just replaces Unity's Instantiate with Spawn. A prefab goes in and an instance comes out.

You should be getting a random PREFAB to Spawn, and NOT a random instance from the pool. All instances in a pool should be thought of as equal. They are just clones of something ready to be used, just like an instance created fresh from a prefab.

If you do need a random instance of a Prefab from the set of already-spawned instances, that can be done via the PoolManager API too, but that doesn't sound like what you are asking. If this ability is not exposed, I'm sure we can get that working if needed.

Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: PaulH on May 23, 2014, 11:48:30 AM
Hi Rafe,

This is Paul. I just emailed Jean regarding this. Yes my game worked fine with the standard playmaker actions using create and destroy, but when i tried to do it using the pool manager actions it was impossible.

all it needed was an action making, i needed a 'select random object from poolManager pool’ action and with the option to store it in a var to spawn later using pool manager spawn action, just like you can with the standard playmaker action selectRandomObject. but no-one did!

i even requested an action in the request action section of this forum http://hutonggames.com/playmakerforum/index.php?topic=7362.0 but got blanked on there as well.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: mweyna on May 23, 2014, 12:50:26 PM
What you want is technically possible now, but will require you to organize your FSM in a specific way. If you want to add objects at runtime into an array, when you spawn them, just use the Array Add playmaker action on them.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: Rafe on May 23, 2014, 01:12:48 PM
...all it needed was an action making, i needed a 'select random object from poolManager pool’ action and with the option to store it in a var to spawn later...

Again, this sounds like you are talking about storing a prefab to be spawned later right? The word "object" is a bit misleading. In Unity we deal in terms of "prefabs" and "instances". If this is the case, were you looking for a way to grab a random prefab from PoolManager? So, not an instance from the pool but rather one of the prefabs you setup using the inspector (or other way of pre-defining a PoolManager PrefabPool)?

If I'm right about all the above, it sounds like you need the PlayMaker equivalent of this PoolManager API code:
Code: [Select]
i = <randomIndex>;  // Psuedo code...I'm assuming you know how to get the random index
string poolName = "RandomStuff";
SpawnPool pool = PoolMananger.Pools[poolName];
Transform randomPrefab = pool.prefabs.Keys()[i];
(...that could be done in one line of code but I broke it up for clarity of types)
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: Rafe on May 23, 2014, 01:15:57 PM
What you want is technically possible now, but will require you to organize your FSM in a specific way. If you want to add objects at runtime into an array, when you spawn them, just use the Array Add playmaker action on them.

This may indeed be the best way in PlayMaker, but PoolManager users have access to members (prefabs and instances) of any pool, anytime, through the static access: PoolManager.Pools[...].... This information may or may not help  ;)
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: mweyna on May 23, 2014, 01:34:20 PM
So depending on the context, you could have an FSM that has an event for each object type and at the start state it random picks one of those events. Say you have 1, 2, 3, 4 as your event names. You'd randomly pick that number with the existing playmaker actions, within each of those Global Transitions in that FSM (1,2,3,4) you'd have a pre-fab definition already assigned to spawn that pre-fab instance.

For my dungeon keeper-esc project I've used that style of setup on my saving and loading to spawn different units where I can't directly reference a prefab object.

Just wanna say Rafe, I'm loving PoolManager, it's singlehandly made my project possible and run with more then 2 FPS.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: PaulH on May 23, 2014, 02:02:30 PM
What you want is technically possible now, but will require you to organize your FSM in a specific way. If you want to add objects at runtime into an array, when you spawn them, just use the Array Add playmaker action on them.

This may indeed be the best way in PlayMaker, but PoolManager users have access to members (prefabs and instances) of any pool, anytime, through the static access: PoolManager.Pools[...].... This information may or may not help  ;)

this is what i was talking about. i couldn't for the life of me see why a action couldn't be made to access the pool using Poolmanager.Pool and pick a random prefab or instance to spawn.

Rafe i know poolManager can do this, but i cant code too much, thats the whole reason for me using playmaker, which is amazing, but when i hit a problem like this im relying on someone else to make the action and it just doesnt/didnt happen and ive watched many other people have similar problems on here.

i'm sure playmaker is making a ton of money, so why not hire another person just for writing actions for all plugins/scenarios that arise? i know they have jean but if you see the trello list hes got loads to do, too much for one person possibly.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: mweyna on May 23, 2014, 02:08:24 PM
The flexibility of Playmaker is that it allows you to create complex code situations without any knowledge of how to code. If I had to wait for someone to create specific project code that I needed I'd never have made any progress on my project. Is it the most efficient way to handle it versus "true programming?" absolutely not. Can you solve these sort of problems without any additional code support, yes. At the end of the day, no one will care about your project or programming needs more then you. Better to develop the habit as much as possible now to solve your issue (even if it isn't the most effective way), and then if someone creates something easier to use that.
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: PaulH on May 23, 2014, 03:30:47 PM
The flexibility of Playmaker is that it allows you to create complex code situations without any knowledge of how to code. If I had to wait for someone to create specific project code that I needed I'd never have made any progress on my project. Is it the most efficient way to handle it versus "true programming?" absolutely not. Can you solve these sort of problems without any additional code support, yes. At the end of the day, no one will care about your project or programming needs more then you. Better to develop the habit as much as possible now to solve your issue (even if it isn't the most effective way), and then if someone creates something easier to use that.

you shouldn't have to find crazy workarounds(and in this case there wasnt one, yours didnt work for me). playmaker isnt cheap, i feel the least they should do is try to have the actions for any scenario, or someone on standby ready to write them if not.

"Artists and Designers: Realize your creative vision without coding! Unlock the power of Unity. "








playmaker is all about the actions obviously,
Title: Re: How to spawn a random object using pool manager/playmaker?
Post by: jeanfabre on May 26, 2014, 04:03:16 AM
Hi,

Ok, I think you are overthinking this.

If you study the action "Pmt Spawn", you'll see that it expects the name of the pool and a reference to a prefab. So basically, your random pick of the prefab you want to spawn has to be done before you call this action.

 I assume the following:

 you have a "spawn pool" name "My Multi Pool" in your scene

in "My Multi Pool", you have created several "per prefab" pool, and each reference a different prefab

use "Select Random GameObject" and list the very same prefabs you used in "My Multi Pool"

Inject the gameobject randomly picked by "Select Random GameObject" action nad use that in "Pmt Spawn" referencing the pool "My Multi Pool".

 that's it.

 Does that makle sense? give it a go, if that doesn't work out, I'll do a working example. You don't need any custom actions, you don't need ArrayMaker. You would need arrayMaker if you want to have more control over the list of prefabs you may randomly pick.

 Now. I can see a potential new custom action that would pick a random per prefab pool item declared in a "spawn pool", so that it would be more intuitive, but it's totally possible without as I explained above.

 Bye,

 Jean