Martin
Martin

Reputation: 67

Unity NewGraph Tool does not handle all cases of Enter Playmode Settings

In a Unity project I'm using the NewGraph node editor and am using a Monobehaviour-based graph (derived from MonoGraphModel). Now when using the following combo of "Enter Playmode Settings" (in the Project Settings) Enter Playmode Settings a MonoGraphModel on a GameObject throws the following error when the GraphWindow is open and entering Play Mode in the editor:

ArgumentException: Object at index 0 is null UnityEditor.SerializedObject..ctor (UnityEngine.Object obj) (at /Users/bokken/build/output/unity/unity/Editor/Mono/SerializedObject.bindings.cs:22) NewGraph.GraphModelBase.CreateSerializedObject (UnityEngine.Object scope, System.String rootFieldName) (at Assets/NewGraph/Models/GraphModelBase.cs:147) NewGraph.MonoGraphModel.CreateSerializedObject () (at Assets/NewGraph/Models/MonoGraphModel.cs:61) NewGraph.MonoGraphModel.get_BaseObject () (at Assets/NewGraph/Models/MonoGraphModel.cs:44) NewGraph.GraphSettings.SetLastOpenedGraphData (NewGraph.IGraphModelData graphData) (at Assets/NewGraph/Editor/Settings/GraphSettings.cs:35) NewGraph.GraphController+<>c__DisplayClass43_0.b__0 () (at Assets/NewGraph/Editor/Controllers/GraphController.cs:452) UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/VisualElementScheduler.cs:346) UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/Scheduler.cs:363) UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:253) UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Core/UIElementsUtility.cs:105) UnityEditor.RetainedMode.UpdateSchedulers () (at /Users/bokken/build/output/unity/unity/ModuleOverrides/com.unity.ui/Editor/RetainedMode.cs:55)

With a ScriptableGraphModel this works fine and without errors. It seems to be an issue with the graph being reloaded at the wrong point in time. In the GraphWindow class, I've already tried to add the LogPlayModeStateChanged callbacks in a method with an attribute of [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] instead of doing that in OnEnable(). I've also played around with explicitly checking for the Playmode Settings like so

    public static void LogPlayModeState(PlayModeStateChange state) {
        if (state == PlayModeStateChange.ExitingPlayMode) {
            window.graphController?.EnsureSerialization();
        } else if (state == PlayModeStateChange.EnteredEditMode) {
            LoadGraph();
        } else if (state == PlayModeStateChange.EnteredPlayMode) {
            
            if (EditorSettings.enterPlayModeOptionsEnabled && 
                (
                (!EditorSettings.enterPlayModeOptions.HasFlag(EnterPlayModeOptions.DisableSceneReload)) &&
                (EditorSettings.enterPlayModeOptions.HasFlag(EnterPlayModeOptions.DisableDomainReload))
                ) 
            )
            {
                return;
            }
            
            window?.graphController?.Reload();
        }
    }

But it seems that the nodes custom node editors for my nodes are just never initialized. Not sure if such a question goes too deep for such a forum, but I thought it might be worth a try before throwing my notebook out of the window. Maybe its just a stupid thing from my side and there is an obvious solution to handling this case.

Upvotes: 1

Views: 72

Answers (0)

Related Questions