playMaker

Author Topic: How to spawn a random object using pool manager/playmaker?  (Read 12566 times)

PaulH

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
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.

« Last Edit: May 20, 2014, 06:46:54 AM by elusive52 »

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #1 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.

PaulH

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #2 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?

« Last Edit: May 19, 2014, 10:18:07 AM by elusive52 »

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #3 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.

PaulH

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #4 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?



« Last Edit: May 19, 2014, 07:56:04 PM by elusive52 »

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #5 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.

PaulH

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #6 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.


mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #7 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.

Rafe

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #8 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.


PaulH

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #9 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.

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #10 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.

Rafe

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #11 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)

Rafe

  • Playmaker Newbie
  • *
  • Posts: 4
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #12 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  ;)

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #13 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.

PaulH

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
Re: How to spawn a random object using pool manager/playmaker?
« Reply #14 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.