0
Not a bug

Floating text NullReferenceException

shristov 2 months ago in Game Creator updated by Marti (Lead Developer) 2 months ago 1

I was trying to figure out why in some cases Floating text generates NullReferenceExeptions. This is what I found:

Simple scene as in screenshot ( two cubes with trigger on start and action floating text ).

If cube1 and cube2 are enabled - hit play – all is OK.

If cube1 is enabled and cube2 is disabled - hit play – enable cube2 – all is OK .

If cube1 and cube2 are disabled – hit play – enable cube1 or cube2 – NullReferenceExeption (screenshot and log below )

NullReferenceException: Object reference not set to an instance of an object

GameCreator.Messages.FloatingMessageManager+d__7.MoveNext () (at Assets/Plugins/GameCreator/Messages/FloatingMessage/Mono/FloatingMessageManager.cs:51)

UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)

GameCreator.Messages.FloatingMessageManager:Show(String, Color, Transform, Vector3, Single) (at Assets/Plugins/GameCreator/Messages/FloatingMessage/Mono/FloatingMessageManager.cs:42)

GameCreator.Messages.d__7:MoveNext() (at Assets/Plugins/GameCreator/Messages/FloatingMessage/ActionFloatingMessage.cs:42)

GameCreator.Core.d__3:MoveNext() (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IAction.cs:34)

GameCreator.Core.d__10:MoveNext() (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:29)

UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)

GameCreator.Core.ActionCoroutine:.ctor(IEnumerator) (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:24)

GameCreator.Core.d__9:MoveNext() (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:109)

UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)

GameCreator.Core.IActionsList:Execute(GameObject, Action, Object[]) (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:91)

GameCreator.Core.Actions:Execute(GameObject, Object[]) (at Assets/Plugins/GameCreator/Core/Mono/Interaction/Actions.cs:96)

GameCreator.Core.Trigger:Execute(GameObject, Object[]) (at Assets/Plugins/GameCreator/Core/Mono/Interaction/Trigger.cs:199)

GameCreator.Core.Igniter:ExecuteTrigger(GameObject, Object[]) (at Assets/Plugins/GameCreator/Core/Mono/Igniters/Igniter.cs:66)

GameCreator.Core.Igniter:ExecuteTrigger(GameObject) (at Assets/Plugins/GameCreator/Core/Mono/Igniters/Igniter.cs:59)

GameCreator.Core.IgniterStart:Start() (at Assets/Plugins/GameCreator/Core/Mono/Igniters/IgniterStart.cs:16)

Same error is observed in a similar scene – one cube only with simple behavior ( task -> floating text ) – NullReferenceExeption. If you have in a scene a second object with floating text action, behavior does not generate error.

Unity version:
2018.4.8 LTS
Game Creator version:
1.0.3

Answer

Answer
Not a bug

This is one of those esoteric issues that seem strange, but make sense once you know them. But first of all, the solution:

Game Creator needs a way to identify the primary camera. This is usually set up when using a Camera Motor, but since you don't have one in your scene you can do one of the following:

  • Tag the Main Camera object with the MainCamera tag
  • Add the Camera Controller component to the Main Camera

Either if them is fine. I'm posting below the explanation of why this is happening, just in case you're interested :-)

The thing is that the first time the Floating Message is set up, it creates a Canvas object and sets it to World Space. In order to appear in world space, it requires a reference to the camera that is going to be used for rendering the UI. And here was the problem: I assumed there's one that either has the "MainCamera" tag or has the HookCamera component (automatically added by the Camera Controller component).

I'l try to improve the message error so it gives you a better idea of what's missing. Thanks for the heads up!

Answer
Not a bug

This is one of those esoteric issues that seem strange, but make sense once you know them. But first of all, the solution:

Game Creator needs a way to identify the primary camera. This is usually set up when using a Camera Motor, but since you don't have one in your scene you can do one of the following:

  • Tag the Main Camera object with the MainCamera tag
  • Add the Camera Controller component to the Main Camera

Either if them is fine. I'm posting below the explanation of why this is happening, just in case you're interested :-)

The thing is that the first time the Floating Message is set up, it creates a Canvas object and sets it to World Space. In order to appear in world space, it requires a reference to the camera that is going to be used for rendering the UI. And here was the problem: I assumed there's one that either has the "MainCamera" tag or has the HookCamera component (automatically added by the Camera Controller component).

I'l try to improve the message error so it gives you a better idea of what's missing. Thanks for the heads up!