playMaker

Author Topic: Infinite loops probably for concurrency of actions in the same state? [SOLVED]  (Read 1245 times)

Porchetto Game Dev

  • Playmaker Newbie
  • *
  • Posts: 3
Hey guys, I'm facing a weird behaviour with Playmaker and scriptable objects.

I've made a custom actions to get and set values to scriptable objects that have the same type of the playmaker variables.

When I set that a variable should get the value from the SO every frame, it acts really weird, it set the value the first time you enter state as it should, but when you enter the state again, the value of the Playmaker variable doesn't get updated, this lead to infinite loops when doing some checks.

I'll leave you actions, SOs and FSM screenshots and code so you can have a complete picture of the thing.



Here I have to reset the value of the playmaker variable to 0 or it will bug badly




So code
Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "ScriptableObjects/Variables/FloatVariable")]
public class FloatVariable : ScriptableObject
{
    public float value;
}

Custom Action Code

Code: [Select]
using HutongGames.PlayMaker;
using System.Collections;
using System.Collections.Generic;

[ActionCategory(ActionCategory.ScriptControl)]

public class GetFloatVariableValue : FsmStateAction
{
    [Tooltip("The value to pass")]
    public FloatVariable ScriptableObjectFloat;

    [Tooltip("The variable to set")]
    public FsmFloat floatVariable;

    public FsmBool everyFrame;


    public override void Reset()
    {
        floatVariable = null;
        everyFrame = false;
    }

    public override void OnEnter()
    {
        if (!everyFrame.Value)
        {
            SetValue();
            Finish();
        }
    }

    public override void OnUpdate()
    {
        if (everyFrame.Value)
        {
            SetValue();
        }
    }

    private void SetValue()
    {
        if (ScriptableObjectFloat != null)
        {
            floatVariable.Value = ScriptableObjectFloat.value;
        }
    }
}

Code: [Select]
using HutongGames.PlayMaker;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ActionCategory(ActionCategory.ScriptControl)]
public class SetFloatVariableValue : FsmStateAction
{
    public FloatVariable ScriptableObjectFloat;

    public FsmFloat FloatVariable;

    public FsmBool everyFrame;


    public override void Reset()
    {
        FloatVariable = null;
        everyFrame = false;
    }

    public override void OnEnter()
    {
        if (!everyFrame.Value)
        {
            SetValue();
            Finish();
        }
    }

    public override void OnUpdate()
    {
        if (everyFrame.Value)
        {
            SetValue();
        }
    }

    private void SetValue()
    {
        if (ScriptableObjectFloat != null)
        {
            ScriptableObjectFloat.value = FloatVariable.Value;
        }
    }
}


I was testing stuff with another project and I think the problem might be a concurrency of the actions, because FSM variables get updated, but still it keeps going crazy. If I want the Comparison on the vector2 every frame but it must happens after all the actions are done, what I must do?

I'm sorry if it might seems a stupid question but I'm used to normal code where things happens in order (here seems not), I'm new to playmaker and trying to learn the ropes.

« Last Edit: May 08, 2022, 12:43:15 PM by Porchetto Game Dev »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Hi.
One thing i noticed is inside OnEnter

SetValue(); should be outide the 'if' part,
as SetValue will not be called on OnEnter this way.

Also on update the if check is obsolete here's a sample on how i would set it up.
(i don't know if it will fix your issue tho)

Code: [Select]
using HutongGames.PlayMaker;

[ActionCategory(ActionCategory.ScriptControl)]

public class GetFloatVariableValue : FsmStateAction
{
    [Tooltip("The Scriptable Object")]
    [RequiredField]
    public FloatVariable ScriptableObjectFloat;

    [Tooltip("The variable to Get")]
    public FsmFloat floatVariable;

    public FsmBool everyFrame;


    public override void Reset()
    {
        floatVariable = null;
        everyFrame = false;
    }

    public override void OnEnter()
    {
        SetValue();

        if (!everyFrame.Value) Finish();
    }

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

    private void SetValue()
    {
        floatVariable.Value = ScriptableObjectFloat.value;
    }
}

Porchetto Game Dev

  • Playmaker Newbie
  • *
  • Posts: 3
Nope man, unfortunately didn't solve the problem, still getting infinite loop on this FSM


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Hi.
you probably need some tolerance or add a next frame event in between.

by the way on the bottom right of the playmaker window there is a checkbox called 'Debug'
You can turn that on to see the variables (also during gametime)

have you updated the Set Float action script as well?

Porchetto Game Dev

  • Playmaker Newbie
  • *
  • Posts: 3
Hey man, I solved the problem, it was a "design mistake" and a user on the discord server gave me the solution to it.
I should have done the comparison on a vector that stored both the values (this way it works.
I think that multiple comparisons actions should be made, prolly I'll do something on my own.
Still, thank you for reaching me out and for the corrections on the custom actions!
If you have an updated tutorial on how to make them, pls share it, because I really need it!