0
Fixed

OnEnable is called twice [1.4.0]

cooloon 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 2

If you instantiate an inactive prefab with embedded FlowGraph, then calling SetActive(true) on the instance of that prefab triggers OnEnable event twice. My test code is this:

using UnityEngine;
public class Test : MonoBehaviour
{
    public Bolt.FlowMachine prefab; // GameObject is inactive
    void Start()
    {
        var flowMachine = Instantiate(prefab);
        flowMachine.gameObject.SetActive(true);
    }
}

And the graph is just like: [OnEnable ]--> [Debug.Log("OnEnable")]

The two call stack of those events are:

OnEnable
System.Runtime.CompilerServices.ExecutionScope:lambda_method(ExecutionScope, Object)
Ludiq.StaticActionInvoker`1:InvokeUnsafe(Object, Object) (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Reflection/Optimization/StaticActionInvoker_1.cs:51)
Ludiq.StaticActionInvoker`1:Invoke(Object, Object) (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Reflection/Optimization/StaticActionInvoker_1.cs:32)
Ludiq.Member:Invoke(Object) (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Reflection/Member.cs:908)
Bolt.InvokeMember:Invoke(Flow)
Bolt.InvokeMember:Enter(Flow)
Bolt.Flow:InvokeDelegate(ControlInput)
Bolt.Flow:Invoke(ControlOutput)
Bolt.Flow:Run(ControlOutput, Boolean)
Bolt.EventUnit`1:Run(Flow)
Bolt.EventUnit`1:Trigger(GraphReference, EmptyEventArgs)
Bolt.<>c__DisplayClass14_0:<startlistening>b__0(EmptyEventArgs)
Bolt.EventBus:Trigger(EventHook, EmptyEventArgs)
Bolt.EventMachine`2:TriggerRegisteredEvent(EventHook, EmptyEventArgs)
Bolt.EventMachine`2:TriggerEvent(String)
Bolt.EventMachine`2:OnEnable()
Bolt.FlowMachine:OnEnable()
Bolt.EventMachine`2:AfterGraphChange()
Ludiq.GraphNest`2:AfterGraphChange()
Ludiq.GraphNest`2:Awake()
Ludiq.Machine`2:Awake()
Bolt.EventMachine`2:Awake()
UnityEngine.GameObject:SetActive(Boolean)
Test:Start() (at Assets/Test.cs:10)</startlistening>

and

OnEnable
System.Runtime.CompilerServices.ExecutionScope:lambda_method(ExecutionScope, Object)
Ludiq.StaticActionInvoker`1:InvokeUnsafe(Object, Object) (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Reflection/Optimization/StaticActionInvoker_1.cs:51)
Ludiq.StaticActionInvoker`1:Invoke(Object, Object) (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Reflection/Optimization/StaticActionInvoker_1.cs:32)
Ludiq.Member:Invoke(Object) (at C:/Users/lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Reflection/Member.cs:908)
Bolt.InvokeMember:Invoke(Flow)
Bolt.InvokeMember:Enter(Flow)
Bolt.Flow:InvokeDelegate(ControlInput)
Bolt.Flow:Invoke(ControlOutput)
Bolt.Flow:Run(ControlOutput, Boolean)
Bolt.EventUnit`1:Run(Flow)
Bolt.EventUnit`1:Trigger(GraphReference, EmptyEventArgs)
Bolt.<>c__DisplayClass14_0:<startlistening>b__0(EmptyEventArgs)
Bolt.EventBus:Trigger(EventHook, EmptyEventArgs)
Bolt.EventMachine`2:TriggerRegisteredEvent(EventHook, EmptyEventArgs)
Bolt.EventMachine`2:TriggerEvent(String)
Bolt.EventMachine`2:OnEnable()
Bolt.FlowMachine:OnEnable()
UnityEngine.GameObject:SetActive(Boolean)
Test:Start() (at Assets/Test.cs:10)</startlistening>
Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
GOOD, I'M SATISFIED
Satisfaction mark by cooloon 2 years ago
Working on Fix

Working on fix today!

+1
Fixed

Found cause & applied tentative fix, will be included in today's hotfix.