playMaker

Author Topic: Variables (in FSM instances and prefabs) not reset after playmode end  (Read 964 times)

Nikaas

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
State machine variables doesn't seem to revert back to initial values at the end of playmode - this happens in the scene object and more strangely in its prefab too. The var change must be during action's Awake().


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12539
  • Official Playmaker Support
    • View Profile
Re: Variables (in FSM instances and prefabs) not reset after playmode end
« Reply #1 on: February 06, 2017, 10:45:14 PM »
Hi,

 Is it not an interface glitch? if you click and browse other fsm and back values persists?

 Bye,

 Jean

Nikaas

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Variables (in FSM instances and prefabs) not reset after playmode end
« Reply #2 on: April 24, 2017, 11:57:19 AM »
They persist.

But what I noticed is that this only happens if the gameObject/prefab is selected when hitting play. The FSM parent is even disabled on playmode (i.e. there is  gameObject.SetActive(false) at the parent's Awake). All tests i done were on the starting state.

Additionally I noticed this happens if the vars are set at OnEnter, but there only FSMGameObject persist.
« Last Edit: April 24, 2017, 11:58:54 AM by Nikaas »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12539
  • Official Playmaker Support
    • View Profile
Hi,

Sorry for the delay :) please bump when you see that I lost track of posts.

 can you tell your version of Unity? I assume you have the latest version of PlayMaker right?

Bye,

 Jean

Nikaas

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Unity is 5.6.0f3 and Playmaker 1.8.4.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12539
  • Official Playmaker Support
    • View Profile
Hi,

 that's very odd, I can find a way to repro this.

 Could you make a screencast showing what you do, then I may be able to understand what exactly is happening. That would really help as I can't fault this.

Bye,

 Jean

Nikaas

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Here is a video: https://youtu.be/zm4M422Yttk

Notice how the int value is adding up on each run only when the game object / prefab is selected.

The code of the action is
Code: [Select]
public class Add : FsmStateAction
{
public FsmInt intVariable;
public FsmInt add;

public override void Awake()
{
intVariable.Value += add.Value;
}

public override void OnUpdate()
{
Finish();
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12539
  • Official Playmaker Support
    • View Profile
Hi,

 I see, I completly miss out on the awake thing. d'oh... :)

 indeed, you should only use OnEnter and OnUpdate and Reset when you want to work with variables.

If you put a log in the awake you 'll see that awake if called on this action even if you use the action in a state that is not active. put a wait of 2 seconds in the start state and transit to a state where you use this action. the log is right when the fsm is initialized, not when the active state becomes the one with that action.

 Bye,

 Jean

Nikaas

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Same happens in OnEnter and OnUpdate but only for FsmGameObject variables (there could be others, I haven't tried all var types).

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12539
  • Official Playmaker Support
    • View Profile
Hi,

 I can't repro this, can you paste a code snippet for me to test?

Thanks,

 Bye,

 Jean

Nikaas

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Variables (in FSM instances and prefabs) not reset after playmode end
« Reply #10 on: January 06, 2018, 07:29:07 PM »
I still can't get it if FSM variables should reset to pre-play mode values or they should remain to what they were changed-to during play mode (contrary to everything else in unity)?

If the FSM game object is selected in the hierarchy at the moment of clicking Stop the values are not reset, but if some other game object is selected at stop then the values are reset.

Next is a video how PM behaves differently in the 2 cases - https://youtu.be/3Oo-V9xTiiM


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3244
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Variables (in FSM instances and prefabs) not reset after playmode end
« Reply #11 on: January 06, 2018, 08:47:53 PM »
Are you still using 1.8.4? 
Have you tried in 1.8.6?

Nikaas

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Variables (in FSM instances and prefabs) not reset after playmode end
« Reply #12 on: January 07, 2018, 12:29:44 AM »
I'm now with 1.8.6.

Nikaas

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Variables (in FSM instances and prefabs) not reset after playmode end
« Reply #13 on: January 07, 2018, 05:19:03 PM »
In the end the Awake() method in the actions is called as a consequence of OnInspectorGUI() (only when the game object is selected). And that happens after Stop is clicked.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12539
  • Official Playmaker Support
    • View Profile
Re: Variables (in FSM instances and prefabs) not reset after playmode end
« Reply #14 on: January 10, 2018, 12:41:24 AM »
Hi,

 yeah, Ok I see. I will forward this to Alex, maybe this is something that can be improved to lift any misunderstanding.

 Bye,

 Jean