playMaker

Author Topic: Help: Why are instances of a prefab using the same variables?  (Read 2069 times)

Lesane

  • Playmaker Newbie
  • *
  • Posts: 3
Help: Why are instances of a prefab using the same variables?
« on: August 03, 2016, 02:24:22 AM »
I have a prefab that I add to a scene multiple times, the prefab has an FSM on it and this then shows that each instance in the scene has what looks to be a copy of the FSM. When I run through my FSM it basically will set a bool say when I clicked on an object in the the scene. When I look at the other objects that have been made from the prefab they all have this variable set to true. I was hoping that each FSM on an instance of a prefab would be different thus this variable would be false on all of them except the one that I clicked on which would be set to true.

Am I doing something wrong or am I missing understanding something or is this a bug?

Thanks
« Last Edit: August 03, 2016, 02:40:14 AM by Lesane »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Help: Why are instances of a prefab using the same variables?
« Reply #1 on: August 03, 2016, 04:28:24 AM »
Hi,
What action are you using?

If you are using "mouse down" it will trigger anywhere on the scene
you should try using "mouse pick event"
But if you will have many objects you may want to do it diferently.
if so, let me know, then i will make a quick video to explain how to do it.

Lesane

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Help: Why are instances of a prefab using the same variables?
« Reply #2 on: August 03, 2016, 10:21:33 PM »
Let me explain in more detail

I have a start state of waitforclick with a GetMouseButtonDown action and a clicked event. The action sends a Clicked event this leads to a state2 state with a mouse pick action and a game object compare tag action the mouse pick action stores the game object that was clicked in a floorclicked variable the game object compare tag gets the floorclicked variables tag and compares it to the tag dirt which all floor objects have this then sends a floorclicked event on true and a cancel event on false.

The cancel goes back to the wait for click and the floorclicked goes to the next state that has a cancel event and a canhoe event this state has an action of bool test that checks the variable hoed on true it goes to cancel leading back to waitforclick and on false it goes to canhoe leading to the last state.  the last state has a set material color action that takes the floorclicked variable set in the state2 and sets its color to a shade of brown it also has a set bool value action  that sets hoed to true.

when i put this on a single floor tile it works as expected but when I put this on two floor tiles the first click works as expected but the second click on the other tile has the hoed variable also set to true. My expectation is that this is two different fsms so the variable hoed should be set to false on that one thus doing what a state machine is meant to do 'keep state'. I have attached screen shots of the the fsm and the actions.

Thanks


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Help: Why are instances of a prefab using the same variables?
« Reply #3 on: August 04, 2016, 06:40:34 AM »
Hi,
If i understand right what you are doing, you should have this fsm on an empty object. (or somewhere else)
Then after "mouse pick" use "get fsm bool" to get the bool from the picked object.
Then do the bool test, and use set fsm bool to set the bool value of the object.

So on the floor tiles you would only have an empty fsm (or an fsm doing something different) and a bool variable.



Lesane

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Help: Why are instances of a prefab using the same variables?
« Reply #4 on: August 05, 2016, 12:23:02 AM »
Thanks for the help djaydino. Although that is really messed up that we have to do that as it looks like the fsm that is running is the one on the object that was clicked but in fact it is the fsm of the prefab that is really running and the variables of the prefab that the set bool and get bool are using. Seems like this is a bug but oh well. it is working now. That way also makes running the game in the unity environment very painful. My little guy freezes for like 1 second or so. When I run it outside of unity it looks to run fine. So cheers and thanks again.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Help: Why are instances of a prefab using the same variables?
« Reply #5 on: August 05, 2016, 09:17:16 AM »
Hi,
Actually it is not a bug the action simply listens if the mouse button has been pressed.

If you want it only to work on an object you should go to : add transition then system events and Select mouse down.

BUT, if you have many objects it is better (cheaper) to use mouse pick.
if you have many objects listening you will lose performance