In my project I have one particular scene which I use to display small Naninovel cutscene scripts. To that end, I've done the following :
Naninovel -> Engine -> Scene Independent = false (I want it to completely go away when the scene is unloaded)
Naninovel -> Resource Provider -> Log Resource Loading = true (I want to log resource loading while in testing)
This combination of options however causes a spew of exceptions when the scene unloads
Code: Select all
MissingReferenceException: The object of type 'Text' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.EventSystems.UIBehaviour.IsActive () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/UIBehaviour.cs:28)
UnityEngine.UI.Graphic.SetVerticesDirty () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Graphic.cs:291)
UnityEngine.UI.Text.set_text (System.String value) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Text.cs:218)
Naninovel.UI.LoadLoggerScrollRect.Log (System.String message) (at Assets/Naninovel/Runtime/UI/Loading/LoadLoggerScrollRect.cs:27)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <1fe4b731108247d3a7e57fad336611b9>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:153)
UnityEngine.UnitySynchronizationContext.Exec () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:83)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:107)
I think the simple solution would just be to check the truthiness of loggerText in LoadLoggerScrollRect before accessing its text, as this resolves the issue on my local setup
Code: Select all
if (loggerText)
{
loggerText.text += message;
loggerText.text += Environment.NewLine;
UIComponent.verticalNormalizedPosition = 0;
if (loggerText.text.Length >
10000) // UI.Text has char limit (depends on vertex count per char, 65k verts is the limit).
loggerText.text = loggerText.text.GetAfterFirst(Environment.NewLine);
}