Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: wheretheidivides on April 24, 2015, 04:15:05 PM
-
OK, you call talked me into changing the way I do variables. I had over 200 global variables and everything worked fine. So now I am re-doing the project with local variables inside of FSMs. However, I am having issues.
Let's start with your manager concept and see if I can get 1 thing working. I have a prefab of a tank. It has several children (pic1). They all need to be referenced as game objects (pic4). Inside each of the child objects are variables that need to be referenced (such as player1-speed-left) (pic3). Each of the many options are variables to they can be changed during the game (slow down or speed up speed).
So, how do I set this up? If I have a game object with player1 variables in it, them how do I reference them in the child? How do I update them in real time and change them. I sort of figured this out but it seems really complicated. OR do I just put 2-3 varaibes in each FSM as needed.
For example: In picture 2 there is 'FL-P1-Tank-Speed-Forward'. Currently the variable is in this FSM. If I set up a game object as a manager, how do I set it and keep it updated? There has to be a simple way to do it. Using a global variable is easy but would like you to show me the local FSM variable way. It'd be nice to get those 200 global variables in several game objects for easy reference.
thanks
-
Who the heck is Gene? :P
I just set up a character and all of that information was spread between multiple fsms on the same gameObject which is the player. One had the speed of the movement, one had the add force object and it would get float value from itself in the other fsm.
Also, I have heard that using "find game object" should also be avoided for optimization purposes.
-
But the variables are on a prefab (tank). If I set up a manager in the hierarcy, I can load them in at the time it is created. However, it is just a copy. if the manager variable gets changed it doesn't change the copy.
-
I would keep all my variables inside the manager and not in the prefabs and I could get the prefabs from the manager.
-
Yeah, but how? If I store the variables in a manager, then create an object from a prefab then what?
- do I copy over the variables the new copy? If so, then the variable are copies. How would I keep them synced without updating every frame
- Is there some other way to refrnce the variables?
I am not sure how to do this.
-
Hi,
yeah, you will have duplicated local variables throughout the fsm in the chain of communication, from manager to the last tiny bit of gameobject or button.
This is called "composition" when you do this in pur scripting. basically you are going to cascade the variable from one fsm to another, either by using Set Fsm XXX or sending an event with the data containing that variable value.
If you want to update everyframe values, I would do the following:
Assuming, the Manager has a "Manager Value" float local variable. and many fsm wants to get this value on update cause it's changing all the time:
1: The Manager MUST have an Fsm called "Manager Data" ( that's how I usually do this, but you can name it what ever make sense for you.
2: each fsm "slaved" to the manager will be sent by the manager a "SLAVE / INIT",
3: all fsm that wants to use a manager variable will listen to that global event
4: when an fsm receive that event, is stores the "sender" of this event in a GameObject local Variable "Manager"
5: Each fo these slaved Fsm have their own "Manager Value" local fsm variable, you can name them "&Manager Value" or something just to visually indicate it's a slaved value
6: use whenever you want in these slaved fsm, "Get Fsm XXX", targeting the "Manager" GameObject received from the "SLAVE / INIT", and save the "Manager Value" into "&Manager Value"
That's one way to go about this.
Does that make sense? Check my IOS VIew Controller sample on the ecosystem, it shows various similar setup.
Bye,
Jean
-
What about a variable from a prefab? Say you have a tank with a speed variable. Once it is created, a game object is set and a float is set. So how do you set the float on the prefab?
-
You can use the actions get event data and set event info, You get the data of the last event that created the object and you can set its variable using the set fsm variable on the object.
-
Hi,
Yep, SebasLive is right, you can do this, or simply, once you created the prefab instance, on the same state, simply use SetFsmXXX on the prefab and when the prefab starts the fsm variable is already set :) you simply need a "contract" or "interface" agreement that the prefab must have an Fsm named "xxx" with a variable of type y named "zzz".
Bye,
Jean
-
or there a video somewhere or a demo scene?
-
Hi,
yeah, I just made a sample on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) demonstrating this:
(https://pbs.twimg.com/media/CDqSWSnUsAAsUOo.png)
so, you'll see
-- how to force fsmVariable values from the manager to the prefab instance
-- how to send an "INIT" event to the instance passing more data
-- how the instance can get a reference of the Manager viy the "INIT" event, and position itself using the manager's position. The additional benefit of this is to allow the instance to communicate back to the manager if wanted.
You'll notice that on start the value forced by the manager is already set properly ( the random Color). and You'll notice also that everything is synchrone, the process of creating, setting variables, sending event, and more work down the line all happens as a single flow, no wait, or next frame update or tricks.
Bye,
Jean
-
thanks. i'll check it out