Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: weavermount on April 03, 2015, 10:14:41 PM

Title: Pass data to a spawned object?
Post by: weavermount on April 03, 2015, 10:14:41 PM
I have FSM that keeps track of the time between mousedown and mouse up, then spawns (via pathological pool manager) a projectile. How to I inform the projectile how long it was charged for (the time between mouse down and mouse up)?

I need to figure out some way to get it that information before it's drawn for the first time. Any best practices? I can think of a lot of akward hacks, but nothing that feels good.

Thanks in advance
Title: Re: Pass data to a spawned object?
Post by: TheBadFeeling on April 04, 2015, 06:46:31 PM
How about having the "creator" save the new object in an object variable when you spawn it -- and immediately after pass the data to it using Set FSM Variable?

/Bad
Title: Re: Pass data to a spawned object?
Post by: weavermount on April 06, 2015, 02:54:50 PM
Turns out I'm just not used to exactly how the two FSMs were timing there states.
I might not be very FSMonic( ... FSM-ly?) but I made an empty "Hold for data" State followed by and "Init" state followed by a "Fly" state. Once I told it to wait for data before using it it cleared up
Title: Re: Pass data to a spawned object?
Post by: Lane on April 06, 2015, 03:06:44 PM
Typically you can spawn and set the data in the same state. For instance using Create Object, storing the reference to the new object and immediately using Set Fsm <type> on that object reference. You could additionally fire an event on that FSM after you've set the data, like a "ready" event that is fired from an empty Start state.

I find that nearly all of my start states are used for initialization. I don't typically require a 'handshake' event like that, but it seems like a good idea.
Title: Re: Pass data to a spawned object?
Post by: jeanfabre on April 07, 2015, 03:20:09 AM
Hi,

 yep, I confirm Lane's post. instanciate your prefab, and set fsm variables on it directly, it works.

 I usually have a small handshake like an "INIT" global event or something when I need asynchronous process, typically, if the operation involving the creation of the instance has more to do after to get everything setup.

It's also good to send a quick "INIT", because then the instance can get who sent that INIT event ( using get event info action) and talk back very easily (without the need for global variables :) )


 Bye,

 Jean