Forum rules - please read before posting.

[Bug Report]: Variable:Copy action throws error when trying to set a component var as target

edited February 2020 in Engine development

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:

  • I add the "Variable:Copy" action
  • I set the "copy to" section to "Component"
  • I open the "Select Variables" popup from the "'New' Component" button
  • I choose either of the variables in the selector …

… 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 …

Comments

  • edited February 2020

    OK, there is another misbehaviour when I choose a different procedure:

    • Set the "From source" to Component.
    • Choose 1st component var in " 'Old' component". -> A new selector appears below, labeled 'From variable"
    • Set the "To source" to Component.
    • Choose 2nd component var in " 'New' component". -> No error this time!!! -> A new selector appears below, again labeled 'From variable" and providing the available variables from the 1ST component var instead of the 2ND! Still no error, though.
    • Set the "-> 'From' Variable" selector of the "From Source" section from "no parameter" to a parameter …

    … 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:

    newVariableID = ShowVarGUI (oldVariables.vars, null, ParameterType.ComponentVariable, newVariableID, newParameterID, false);
    

    with:

    newVariableID = ShowVarGUI (newVariables.vars, null, ParameterType.ComponentVariable, newVariableID, newParameterID, false);
    
  • edited February 2020

    Not entirely, I am afraid (although the error has vanished indeed):

    • I add the Variable:Copy Action to a scene-based actionlist with parameters.
    • I set both " 'From' source" and " 'To' source" to Component
    • I leave the " 'Old' component" untouched for now and set the " 'New' Component" first …

    … 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:

    • set the " 'to variable" selector (which is still labelled "from") at the very bottom of the action to a variable of the type "integer"
    • and the set the "-> 'From' variable" selector to a parameter that delivers an integer variable (it definitely does, I double-checked it!)

    … 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.

  • edited February 2020

    Visual issues aside, I can't reproduce an issue with the Action's runtime behaviour.

    The selector stays at "no parameter".

    This is the -> 'From' variable: selector?

    How/when are you setting the Component parameter's value?

  • edited February 2020

    This is the -> 'From' variable: selector?

    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.

  • edited February 2020

    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.

  • edited February 2020

    I repeated the test with a fresh and totally reduced setup:

    • Created two empty Game Objects.
      ** Added a variables component to both.
      *** Added one integer variable only to both.
    • Created a new Cutscene with one parameter (A) only: a component var.
    • Added only one variable:copy action to this cutscene.
    • Set the From source selector to "parameter (A)" -> selector stays at "parameter A"
    • Try to choose a Game Object from the "To source" Select Variables selector -> From source parameter selector reverts to "no parameter".
  • edited February 2020
  • All right. Try this full replacement of the ActionVarCopy.cs script:

    https://paste.ofcode.org/YhJDuSbaq3QJAWMpUD7eRA

  • That works – great, Chris, thank you!

  • edited February 2020

    There is one more question in context with component variables and parameters, just for clarity:

    • When setting up interaction parameters for an actionlist (A) that refer to a Variables component, I'll have to specify which component's carrying game object and which of its variables to set – of course!
    • When creating the parameters for that actionlist (A), I can not only set a parameter's "type" to component variable, but also again (!) specify one of the available "Variables component" game objects (or not specify it and leave it at "None").

    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?

  • edited February 2020

    Yes, sure – actually I am trying to stick to AC's nomenclature … ;-)

    • By "setting up interaction parameters" I refer to the 'Set Interaction Parameters' component that can be attached to a hotspot:
    • By "creating parameter" I refer to the 'Create new parameter' label of the button at the bottom of the Interaction (Script) component that belongs to the hotspot's interaction, which appears when "set parameters" is checked:

    Both allow my to assign a specific Game Object with a Variables component attached (which I did in this example) …

  • I see.

    is the purpose of that second specification just the option to define a default value if desired (which is what I assume)?

    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! :-)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.