Cannot access value of GameObject (via GetField or GetProperty task)

scornflake

New member
Perhaps I'm going about this wrong, but if I try to setup a 'get property' or 'get field', the editor throws an exception and the UI goes blank.
I'm doing this inside am externally saved BT. That is passed a single GameObject, from which I want to get the transform.

The variable 'target' is of type GameObject, and isn't assigned at edit time.

1. Here are the vars:

TaskVars.PNG


2. Trying to get a transform from the gameobject:

AboutToClickDynamic.PNG


3. When I click Dynamic, I get the exception:

BrokenUI.PNG



Any ideas?


---


Finally, here's a dump of (one of) the exceptions:

NullReferenceException: Object reference not set to an instance of an object
BehaviorDesigner.Editor.TaskInspector.DrawReflectionField (BehaviorDesigner.Runtime.Tasks.Task task, UnityEngine.GUIContent guiContent, System.Boolean drawComponentField, System.Reflection.FieldInfo field) (at <6224ec08a63b4190a0704159812b1ad4>:0)
BehaviorDesigner.Editor.TaskInspector.DrawSharedVariableValue (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Reflection.FieldInfo field, UnityEngine.GUIContent guiContent, BehaviorDesigner.Runtime.Tasks.Task task, BehaviorDesigner.Runtime.SharedVariable sharedVariable, System.Boolean isReflectionTask, System.Boolean enabled, System.Boolean drawWatch) (at <6224ec08a63b4190a0704159812b1ad4>:0)
BehaviorDesigner.Editor.TaskInspector.DrawObjectFields (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, BehaviorDesigner.Editor.TaskList taskList, BehaviorDesigner.Runtime.Tasks.Task task, System.Object obj, System.Boolean enabled, System.Boolean drawWatch) (at <6224ec08a63b4190a0704159812b1ad4>:0)
BehaviorDesigner.Editor.TaskInspector.DrawTaskFields (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, BehaviorDesigner.Editor.TaskList taskList, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean enabled) (at <6224ec08a63b4190a0704159812b1ad4>:0)
BehaviorDesigner.Editor.TaskInspector.DrawTaskInspector (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, BehaviorDesigner.Editor.TaskList taskList, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean enabled) (at <6224ec08a63b4190a0704159812b1ad4>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.DrawPropertiesBox () (at <6224ec08a63b4190a0704159812b1ad4>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.Draw () (at <6224ec08a63b4190a0704159812b1ad4>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.OnGUI () (at <6224ec08a63b4190a0704159812b1ad4>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:310)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean customBorder, System.Boolean floatingWindow, System.Boolean isBottomTab) (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:361)
UnityEditor.DockArea.OldOnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:320)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:266)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:438)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent () (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:412)
UnityEngine.Experimental.UIElements.ImmediateStylePainter.DrawImmediate (System.Action callback) (at C:/buildslave/unity/build/Modules/UIElements/ImmediateStylePainter.cs:113)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoRepaint (UnityEngine.Experimental.UIElements.IStylePainter painter) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:98)
UnityEngine.Experimental.UIElements.VisualElement.Repaint (UnityEngine.Experimental.UIElements.IStylePainter painter) (at C:/buildslave/unity/build/Modules/UIElements/VisualElement.cs:845)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater.PaintSubTree (UnityEngine.Experimental.UIElements.VisualElement root, UnityEngine.Matrix4x4 offset, System.Boolean shouldClip, System.Boolean shouldCache, UnityEngine.Rect currentGlobalClip) (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeRepaintUpdater.cs:310)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater.PaintSubTreeChildren (UnityEngine.Experimental.UIElements.VisualElement root, UnityEngine.Matrix4x4 offset, System.Boolean shouldClip, System.Boolean shouldCache, UnityEngine.Rect textureClip) (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeRepaintUpdater.cs:328)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater.PaintSubTree (UnityEngine.Experimental.UIElements.VisualElement root, UnityEngine.Matrix4x4 offset, System.Boolean shouldClip, System.Boolean shouldCache, UnityEngine.Rect currentGlobalClip) (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeRepaintUpdater.cs:314)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater.Update () (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeRepaintUpdater.cs:35)
UnityEngine.Experimental.UIElements.VisualTreeUpdater.UpdateVisualTree () (at C:/buildslave/unity/build/Modules/UIElements/VisualTreeUpdater.cs:70)
UnityEngine.Experimental.UIElements.Panel.Repaint (UnityEngine.Event e) (at C:/buildslave/unity/build/Modules/UIElements/Panel.cs:507)
UnityEngine.Experimental.UIElements.UIElementsUtility.DoDispatch (UnityEngine.Experimental.UIElements.BaseVisualElementPanel panel) (at C:/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:230)
UnityEngine.Experimental.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:68)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)
 
This is an interesting use case and one that I hadn't though of. I'll get it fixed and send you the fixed version through PM. What version of Unity are you running?
 
Hi Justin. 2018.3.4f1 (I think I tried the 3.3something and it did the same as well). Thanks for taking a look :)

I did later find the GameObject->Transform task, which is what I'm using at the moment. Coming from a coding background myself tho, I'd rather have a more general way of extracting nested properties from objects.

This does lead me to another question: should those dropdowns in the 2nd pic (where one is red) also have the right-hand-arrow allowing me to select a property of existing objects? i,e: allow me to map to existing objects properties?
 
should those dropdowns in the 2nd pic (where one is red) also have the right-hand-arrow allowing me to select a property of existing objects? i,e: allow me to map to existing objects properties?
When you enter a GameObject/Component name the Property field should update with what property that you want to use. This is dynamically loaded by the editor though so because dynamic variables are determined at runtime this is a really unique use case. For GetProperty I've only seen the variable names typed in directly and not used shared variables because you're going to need to keep the names of the component name and property name variables in sync and generally is tougher to maintain.
 
OK. It might be worth mentioning that I was only trying the property method ... because I don't know what I'm doing with BD :)
Really I was just wanting to make some existing property (such as transform.position) available to some other task, and it didn't seem I could "arrow select" from existing task level variables, directly into a task. e.g: On IsAlive be able to use an arrow select to choose from the shared variable 'taget', it's "transform" property.

I wonder if some/all of my trouble is that I'm approaching this from the perspective of coding....
 
For always getting the position I recommend using Variable Mappings - it happens that the image on this page actually shows getting the position :) With variable mappings you'll ensure that you always have the latest position and you don't have to use a separate task specifically for that use case.
 
@Justin Is it possible / recommendable using Variable Mappings if your BD Tree is into a Prefab Agent?
I mean because when you select the Variable Mapping in the editor's tree you can reference all the objects in the scene, and that is not allowed on a prefab. Anyway is it possible to map just the Agent where the Tree lives? (Rest of the scene is not possible to be referenced, but I wonder if the Agent (prefab) can.
I'm asking this because sometimes I get lots of errors of mapping Health /ammo on the demo scene if I assign the Agent into a prefab.

Also to mention that is a external tree.

This is the error I get:

Error: Unable to find component on Behavior for property mapping with variable Ammo
UnityEngine.Debug:LogError(Object)
BehaviorDesigner.Runtime.SharedVariable`1:InitializePropertyMapping(BehaviorSource)
BehaviorDesigner.Runtime.JSONDeserialization:DeserializeSharedVariable(Dictionary`2, IVariableSource, Boolean, List`1)
BehaviorDesigner.Runtime.JSONDeserialization:DeserializeVariables(IVariableSource, Dictionary`2, List`1)
BehaviorDesigner.Runtime.JSONDeserialization:Load(TaskSerializationData, BehaviorSource)
BehaviorDesigner.Runtime.BehaviorSource:CheckForSerialization(Boolean, BehaviorSource)
BehaviorDesigner.Runtime.Behavior:CheckForSerialization()
BehaviorDesigner.Runtime.BehaviorManager:EnableBehavior(Behavior)
BehaviorDesigner.Runtime.Behavior:EnableBehavior()
BehaviorDesigner.Runtime.Behavior:Start()
 
Last edited:
You'll be able to map the variable if the component is on the prefab, but you won't be able to map it to other GameObjects that exist within the scene.
 
Top