Null Unity objects cause error when value prediction is enabled

NeedsLoomis 4 years ago updated by Lazlo Bonin (Lead Developer) 4 years ago 8

I was doing more experimenting with variables that are defined in script, and everything seems fine until you use a GameObject, at which point Bolt goes into an infinite log error loop and also shows visual glitches.

Despite the bugging out, everything still acts as expected if you ignore the error spam and click play.

In the below image, the bug would occur the moment you hook "someObject" to the Get Name or Debug command, even though, as you can see in the log, it still runs fine if you ignore it.

sample code:

public class SomeClass : MonoBehaviour
    public int? someInt = null;
    public string someString = null;
    public GameObject someObject;
    void Start ()
        someInt = 4;
        someString = FindObjectOfType<someobject>().gameObject.name;
        someObject = FindObjectOfType<someobject>().gameObject;

Note: I forced nulls just to double check.

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Pending Review


I'm unable to reproduce this bug. Please paste the stack trace when you mention errors. What exact errors do you get when you connect the ports? Do you only get it in play mode or in edit mode as well?

Only in edit mode, only when viewing the specific flow graph.  In play mode, it appears the null GameObject gets immediately replaced with the target and no errors occur. I'll update this post with more info when I get back to my work computer tomorrow, hopefully it's just something simple on my end.

Edit: So I made a new project with a fresh install of bolt 1.0.1 (from the asset store), no changes to anything except I chose programmer names.  Setup a simple scene and everything seemed fine, hit play and worked as expected, hit stop and went back to the graph window, opened the flow machine and immediately got the infinite spam problem again.  

UnassignedReferenceException: The variable testObject of TestScript has not been assigned.
You probably need to assign the testObject variable of the TestScript script in the inspector.
Ludiq.TypeUtility.ToShortString (System.Object o, Int32 maxLength) (at C:/Users/Lazlo/Projects/Ludiq/Ludiq.Core/Runtime/Reflection/TypeUtility.cs:725)
Bolt.ValueConnectionWidget.DrawForeground () (at C:/Users/Lazlo/Projects/Ludiq/Bolt.Flow/Editor/Connections/ValueConnectionWidget.cs:53)
Ludiq.Canvas`1[TGraph].DrawWidgetsForground () (at C:/Users/Lazlo/Projects/Ludiq/Ludiq.Graphs/Editor/Canvases/Canvas.cs:1087)
Ludiq.Canvas`1[TGraph].OnGraphGUI () (at C:/Users/Lazlo/Projects/Ludiq/Ludiq.Graphs/Editor/Canvases/Canvas.cs:87)
Ludiq.GraphWindow.OnGUI () (at C:/Users/Lazlo/Projects/Ludiq/Ludiq.Graphs/Editor/Windows/GraphWindow.cs:157)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:272)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:265)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:232)

heres the scene in its entirety.  The moment I connect the nodes I get the spam.  As you can see in the log, it works fine, beyond the annoying errors.

Two scripts in the scene, a blank MonoBehavior (SomeOtherObject) on the object to reference(GameObjectToFind), and this TestScript on the FSM object:

public class TestScript : MonoBehaviour {
    public GameObject testObject;
    void Start ()
        testObject = FindObjectOfType<SomeOtherObject>().gameObject;    

Hm, that's a very weird error (Unity should just return null and not throw an exception), but for now to avoid it you can uncheck the Values toggle in the toolbar. I'll look into it for v.1.0.2.

The values trick is a nice workaround, thanks!