playMaker

Author Topic: any body know how to.....  (Read 4327 times)

devotid

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
any body know how to.....
« on: May 03, 2012, 10:06:41 AM »
Anyboby know how to enable an FSM on a "Cloned created game object"? (ie; one that is not in the scene until "cloned in"

my game object is not in the scene at start so i cannot directly link to the FSM until its loaded.

I tried the enable FSM action and then pointed it to the name of the FSM manually but it WILL NOT enable it.

If i manually tick the FSM component in the inspector view during run time, the game works as planned.  I just cannot enable an fsm on a cloned object.  I am sending it from another fsm in the scene that is there the whole time.

Any body done this?

Thanks

Kevin

justifun

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 228
    • View Profile
Re: any body know how to.....
« Reply #1 on: May 03, 2012, 08:20:36 PM »
When you create the cloned game object, you need to "store" the newly created object name into a variable, then you can use enable fsm with that store game object variable

is that what you are trying to do?

devotid

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: any body know how to.....
« Reply #2 on: May 10, 2012, 01:32:00 PM »
When you create the cloned game object, you need to "store" the newly created object name into a variable, then you can use enable fsm with that store game object variable

is that what you are trying to do?

I am already storing the cloned object as a gameobject varialable and thats working fine. But im having trouble affecting the fsm's on the cloned object.  i dont think i could find them..... i mean there in the project view....but it wont let me drag them into the fsm areas unless the gameobject is in the hierarchey view.

Im trying to do exactly what you said as that "seems obvious" :) but its not working. 

This was a week ago during a 20 hour work bender and put this post up in desperation....i will try it again tonight and see if i can find a way to "affect" the newly cloned FSM's

Thanks for your help.




justifun

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 228
    • View Profile
Re: any body know how to.....
« Reply #3 on: May 10, 2012, 01:39:57 PM »
Can you explain more about what you mean by "affect the newly cloned fsms"?

you should be able to reference them at any time by using the variable name as the game object instead of "owner" from other FSM's

devotid

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: any body know how to.....
« Reply #4 on: May 11, 2012, 08:47:19 AM »
Can you explain more about what you mean by "affect the newly cloned fsms"?

you should be able to reference them at any time by using the variable name as the game object instead of "owner" from other FSM's

Ok.

to start.....i have no cars (game objects) in the scene......just a track with cameras and when the chosen car is "Loaded" or "cloned into the scene" i cannot make the cameras in the scene "smooth follow" the newly created car...... because its not in the game yet and only in the project view i cannot set the smooth follow targets to it.

I guess im just confused with names of things...... I think i just dont know how to reference something that is not in the scene yet.  I can enable the "smooth follow" behavior/componenet but i cannot set the "target"to the newly loaded car.

Example..... i want to switch cars and dont want to have a set of different cameras for each vehicle......i just want to be able to set a components variable and use the same cameras for all the vehicles.

So what action do i use to change the target name of a in-scene camera?...... no matter what i do i cannot seem to access the components or anything unless it is in the scene

Ill try to make a small vid later today.......to show what i mean. 

I will keep trying though as this is one of the only things that i have not figured out.  Everything else has been soo much fun and rewarding.

Thanks
Kevin

justifun

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 228
    • View Profile
Re: any body know how to.....
« Reply #5 on: May 11, 2012, 08:59:54 AM »
Ah ok. Here what you do.

Create a variable called "player car" of a "game object" type

In the state that has your "create object" action that creates your car, in the "store" field of that action, point it to that new "player car" variable

So your newly created car will be called "carprefab(clone)" or whatever your car prefab was. (which you will see in your heirachy at runtime after its spawned.

Now right after the create object action (or anywhere further down your chain of states in your fsm or another fsm all together, wherever you have your "smooth look at" action  - Next to where it says "game object" for the target, press the little 3 line button to the right of it, and it will change to a variable drop down. Here's where you would put the "player car" variable you made earlier. (this is how you toggle between a specific gameobject (which has to be chosen before runtime - or a variable which can dynamically change during runtime)

So now your camera will follow your newly created object at run time.  

The trick is to start looking at the car after its created.

If you ever want to switch to another car lets say, you simply switch the variable to a different game object using the "set game object" action for example.  eg: when the player presses number key 2, then you would switch to car 2.

Does that make sense?

So your general workflow would be....

-Player picks an available car from a list.  The car can be labelled with a tag, or a variable name, or a game object name, however you want to name it. 
-Depending on which car gets selected, a new state spawns the car at the appropriate location and the name of that gameobject is stored into a variable
-Camera is set to follow selected car
-Player can cycle different cars to follow by changing stored variable at any time


Another little thing to keep in mind that's a bit confusing at first with unity.  Is that if you spawned lets say 10 different cars all the same way, they would all be named
prefabname(clone)
prefabname(clone)
prefabname(clone)
prefabname(clone)

Unity actually knows that each of them are different, but to you the creator they all are hard to distinguish apart.

Here's where the "set name" action comes in handy.  After spawning a new object, its good practice to use something like the "set name" to rename the objects name to something more meaningful.  Even just adding a number to the end of it.

So once the first player spawns a car. you should called it "player 1s car" and "player 2s car" etc.
Its easier to keep track of down the road.






« Last Edit: May 11, 2012, 09:09:50 AM by justifun »

devotid

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: any body know how to.....
« Reply #6 on: May 12, 2012, 11:23:49 AM »
Thanks for the reply......:)

I have gotten what you said above and am already assigning the newly spawned game object to a global variable.  When i activate different cameras they call the variable that i have stored when its created.....so that is working fine with all "look at" cameras.

i got that part.

but my problem is playmaker does not have a "action" to make a follow cam (ie follows 5 meters behind and a little up in the air) playmaker only offers the look at action with the changable target. (which works great btw)

Sooooo.....

to get my follow cam i just switch to a different camera and use the standard unity smooth follow script....but this has a variable in it that changes what car it looks at..... i want to be able to adjust that.  i cannot figure out how to "get or set it".  (note i guess i could create a camera already in the spawned game object and make it enabled when i need it....brainstorming here.... that way there would be a "follow cam" with the Target i need already set )

if playmaker had an action to "smooth follow" i would be fine and then i could just call the variable that was saved and stored when i "created or spawned it in"

i hope this is more clear. as i am familiar with the way the variables work and calling them at runtime....but i guess my real question is can i change a unity scripts variable at runtime through playmaker?

THanks very much for all the help your giving me.  I appreciate it.

Kevin


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3605
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: any body know how to.....
« Reply #7 on: May 19, 2012, 11:53:47 PM »
You can do this with Set Property. Drag the Smooth Follow script into the Target Object field then select the "target" property...

But you're right, Playmaker should have a Smooth Follow action...
« Last Edit: May 21, 2012, 10:45:10 AM by Alex Chouls »