Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: AizenSousuke on September 12, 2014, 05:17:29 AM

Title: Spawn from another FSM Graph at a random position.
Post by: AizenSousuke on September 12, 2014, 05:17:29 AM
Hi

I'm trying to spawn a prefab gameobject from a controller gameobject in the scene using an FSM action (Create Object). I've already randomed the values using random float to random the x and y cood of the point where I want to spawn the prefab. However, when I run the FSM the values are there but the spawned prefabs are still at 0,0,0.

What could be the problem here?

I'm very sure I'm storing the values correctly. I wonder why Playmaker couldn't set the transform of my prefab after it instantiate it.
Title: Re: Spawn from another FSM Graph at a random position.
Post by: jess84 on September 12, 2014, 10:14:13 AM
I can't spot anything wrong from the screenshot.

If you pause your game before the Create Object action, is your spawn position variable already set to something other than 0,0,0?

What happens if you manually set the spawn position variable to say 5,5,0 (before runtime) and then create your object - is it in the correct position then? (so without any random setting)
Title: Re: Spawn from another FSM Graph at a random position.
Post by: AizenSousuke on September 12, 2014, 09:10:59 PM
I can't spot anything wrong from the screenshot.

If you pause your game before the Create Object action, is your spawn position variable already set to something other than 0,0,0?

What happens if you manually set the spawn position variable to say 5,5,0 (before runtime) and then create your object - is it in the correct position then? (so without any random setting)

I did try that. The spawn position is updated with the ones I randomed. I also tried manually but the object still is at 0,0,0. No other scripts are interfering with the spawn position except this fsm graph of playmaker.
Title: Re: Spawn from another FSM Graph at a random position.
Post by: jess84 on September 12, 2014, 10:13:56 PM
Oh, it looks like your objects (TapObj) are children of your UI Root object.

I would probably just make them in the top level of your hierarchy, see if that fixed the problem. (they're likely positioned in relation to the UI Root object's settings)
Title: Re: Spawn from another FSM Graph at a random position.
Post by: AizenSousuke on September 13, 2014, 02:05:01 AM
Oh, it looks like your objects (TapObj) are children of your UI Root object.

I would probably just make them in the top level of your hierarchy, see if that fixed the problem. (they're likely positioned in relation to the UI Root object's settings)

They're spawn as a child because it's an ngui sprite object. if I delete the ngui part from the prefab it still spawns at 0,0,0.

Hmm... when I try running the code from the spawned prefab itself I could get it to set the position properly. How come I can't do it from this object o.O