Hello Chris,
the "Variable:Copy" action throws an error (and messes up the UI, too) when I try to set a component variable as target … specifically in the very moment when I select one of the GameObjects from the popup list that carry a variable component.
My setup in detail:
Among all Game Objects in my scene, there are two that have a variable component attached.
During a scene-based actionlist, I want to use the "Variable:Copy" action to copy a value from one component's var to the other component's var. This actionlist makes use of parameters.
The steps that produce the error:
… boom!
There is total of two errors thrown (repeatedly but not always interchangingly):
1.
NullReferenceException: Object reference not set to an instance of an object
AC.ActionVarCopy.ShowGUI (System.Collections.Generic.List`1[T] parameters) (at Assets/AdventureCreator/Scripts/Actions/ActionVarCopy.cs:253)
AC.ActionListEditorWindow.NodeWindow (System.Int32 i) (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:1283)
UnityEngine.GUILayout+LayoutedWindow.DoWindow (System.Int32 windowID) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUILayout.cs:444)
UnityEngine.GUI.CallWindowDelegate (UnityEngine.GUI+WindowFunction func, System.Int32 id, System.Int32 instanceID, UnityEngine.GUISkin _skin, System.Int32 forceRect, System.Single width, System.Single height, UnityEngine.GUIStyle style) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUI.cs:1694)
UnityEditor.EditorWindow:EndWindows()
AC.ActionListEditorWindow:NodesGUI(Boolean, Event) (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:1626)
AC.ActionListEditorWindow:OnGUI() (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:962)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:187)
2.
NullReferenceException: Object reference not set to an instance of an object
AC.ActionVarCopy.ShowGUI (System.Collections.Generic.List`1[T] parameters) (at Assets/AdventureCreator/Scripts/Actions/ActionVarCopy.cs:253)
AC.ActionListEditor.DrawSharedElements (AC.ActionList _target) (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditor.cs:314)
AC.CutsceneEditor.OnInspectorGUI () (at Assets/AdventureCreator/Scripts/Logic/Editor/CutsceneEditor.cs:15)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass55_0.b__0 () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:521)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:187)
From that moment on the actionlist with this action becomes unreadable in the inspector; in the actionlist editor, only the action itself becomes unreadable. In order to resolve the problem, I need to delete the "Variable:copy" action in the actionlist editor again – this is impossible via the cog, though, as the cog gets unrendered, too; I have to select the action and right-click choose "delete selected".
Hang on, there is more …
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
OK, there is another misbehaviour when I choose a different procedure:
… boom!
The errors this time:
1.
NullReferenceException: Object reference not set to an instance of an object
AC.ActionVarCopy.ShowGUI (System.Collections.Generic.List`1[T] parameters) (at Assets/AdventureCreator/Scripts/Actions/ActionVarCopy.cs:253)
AC.ActionListEditorWindow.NodeWindow (System.Int32 i) (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:1283)
UnityEngine.GUILayout+LayoutedWindow.DoWindow (System.Int32 windowID) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUILayout.cs:444)
UnityEngine.GUI.CallWindowDelegate (UnityEngine.GUI+WindowFunction func, System.Int32 id, System.Int32 instanceID, UnityEngine.GUISkin _skin, System.Int32 forceRect, System.Single width, System.Single height, UnityEngine.GUIStyle style) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUI.cs:1694)
UnityEditor.EditorWindow:BeginWindows()
AC.ActionListEditorWindow:NodesGUI(Boolean, Event) (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:1449)
AC.ActionListEditorWindow:OnGUI() (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:962)
UnityEditor.PopupCallbackInfo:SetEnumValueDelegate(Object, String[], Int32) (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorGUI.cs:3167)
2.
NullReferenceException: Object reference not set to an instance of an object
AC.ActionVarCopy.ShowGUI (System.Collections.Generic.List`1[T] parameters) (at Assets/AdventureCreator/Scripts/Actions/ActionVarCopy.cs:253)
AC.ActionListEditorWindow.NodeWindow (System.Int32 i) (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:1283)
UnityEngine.GUILayout+LayoutedWindow.DoWindow (System.Int32 windowID) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUILayout.cs:444)
UnityEngine.GUI.CallWindowDelegate (UnityEngine.GUI+WindowFunction func, System.Int32 id, System.Int32 instanceID, UnityEngine.GUISkin _skin, System.Int32 forceRect, System.Single width, System.Single height, UnityEngine.GUIStyle style) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUI.cs:1694)
UnityEditor.EditorWindow:EndWindows()
AC.ActionListEditorWindow:NodesGUI(Boolean, Event) (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:1626)
AC.ActionListEditorWindow:OnGUI() (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditorWindow.cs:962)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:187)
3.
NullReferenceException: Object reference not set to an instance of an object
AC.ActionVarCopy.ShowGUI (System.Collections.Generic.List`1[T] parameters) (at Assets/AdventureCreator/Scripts/Actions/ActionVarCopy.cs:253)
AC.ActionListEditor.DrawSharedElements (AC.ActionList _target) (at Assets/AdventureCreator/Scripts/ActionList/Editor/ActionListEditor.cs:314)
AC.CutsceneEditor.OnInspectorGUI () (at Assets/AdventureCreator/Scripts/Logic/Editor/CutsceneEditor.cs:15)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass55_0.b__0 () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:521)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:187)
… and all of this takes place on a Mac with OSX 10.13.6 running Unity 2019.3.0f6 with AC 1.70.4
Thanks for the clear steps and details - I shall investigate.
Both are caused by the same issue. To resolve, open up ActionVarCopy.cs and replace line 253:
with:
Not entirely, I am afraid (although the error has vanished indeed):
… which will produce a notification in the actionlist editor saying "The chosen Variables do not share the same Type – a conversion will be attempted" …
… but I haven't even chosen the variables yet – not even one of them!
Now I choose to ignore that note and:
… but this parameter will not get set (even though the variables types match). The selector stays at "no parameter".
Also, if I try to set up the action without using parameters and explicitly define two integer variables in "from" and "to", the mismatch notification persists.
Visual issues aside, I can't reproduce an issue with the Action's runtime behaviour.
This is the -> 'From' variable: selector?
How/when are you setting the Component parameter's value?
Yes, it is.
OK, the way in which the parameter is set goes a rather long way indeed:
It starts at a Hotspot (1).
This Hotspot (1) triggers a Use: interaction (2) with five parameters: 3 of them GameObjects, 1 integer and 1 component variable of the type "integer" (that's the one!). These parameters get set via a "Set interaction parameters" component attached to the Hotspot (1).
The Use: Interaction (2) mainly consists of a Variable:Popup switch action (3) which conditionally runs one of three other scene-based action lists (4, 5 or 6).
Scene-based action list (4) is the one where the trouble happens; it again uses five parameters: these are exactly the five parameters already used by the Use: Interaction (2), and all of them set to the exact same types (3 GOs, 1 Int, 1 CompVar). So the parameters are supposed to get "passed through".
Every part of this process lives in the scene itself, either as hotspot interactions, scene-based actionlists or as component variables attached to game objects. There are no actionlist assets involved.
I just tried to use the Variable: Copy action in the Use: interaction (2) directly, in order to check whether the "passing through" via the variable: popup switch may be involved in the malfunction; unfortunately it is not – the parameters refuses to get set here, too.
I repeated the test with a fresh and totally reduced setup:
** Added a variables component to both.
*** Added one integer variable only to both.
jenswuerfel.com/externalstuff/TheVariableCopyMovie.mov
Watch things happen here … ;-)
All right. Try this full replacement of the ActionVarCopy.cs script:
https://paste.ofcode.org/YhJDuSbaq3QJAWMpUD7eRA
That works – great, Chris, thank you!
There is one more question in context with component variables and parameters, just for clarity:
I am not clear what this second specification does. It is optional?
It does not seem to be mandatory, as I can leave it unset at "None", but will there be some kind of additional matching check enacted whether the two preselected game objects are identical if it is set to something else then "None"?
Or is the purpose of that second specification just the option to define a default value if desired (which is what I assume)?
I'm not clear on the distinction you're making between "setting up" and "creating" parameters for the same ActionList. Can you share screenshots to clarify?
Yes, sure – actually I am trying to stick to AC's nomenclature … ;-)
Both allow my to assign a specific Game Object with a Variables component attached (which I did in this example) …
I see.
Yes. Assiging a Variables component in the ActionList's properties is just a means to expose the variable you wish to set as the default.
Muchas gracias! :-)