Issue Regarding Custom UI

The engine is not working as expected? Documentation is wrong or out of date? Let us know here!
Forum rules
We are not providing support via this forum; it's community-driven. For official support see https://naninovel.com/support/#naninovel-support
Post Reply
tr5414
Posts: 3
Joined: 03 Jul 2021 23:51

Issue Regarding Custom UI

Post by tr5414 »

I'm trying to implement a simple bar as a Custom U.I. I've put it into my U.I resources, but everytime I start the game I get a NullReferenceException and the game wont load after that. Not Sure why this is happening. Any help would be appreciated. Here is a the complete error:

NullReferenceException: Object reference not set to an instance of an object
Naninovel.UI.CustomUI.OnEnable () (at Assets/Naninovel/Runtime/UI/CustomUI.cs:130)
UnityEngine.Object:Instantiate(GameObject)
Naninovel.Engine:Instantiate(GameObject, String, Nullable1, Transform) (at Assets/Naninovel/Runtime/Engine/Engine.cs:293)
Naninovel.UIManager:InstantiatePrefab(GameObject, String) (at Assets/Naninovel/Runtime/UI/UIManager.cs:191)
Naninovel.<InstantiateUIsAsync>d__38:MoveNext() (at Assets/Naninovel/Runtime/UI/UIManager.cs:246)
UniRx.Async.CompilerServices.AsyncUniTaskMethodBuilder:Start(<InstantiateUIsAsync>d__38&) (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/AsyncUniTaskMethodBuilder.cs:133)
Naninovel.UIManager:InstantiateUIsAsync()
Naninovel.<InitializeAsync>d__37:MoveNext() (at Assets/Naninovel/Runtime/Engine/Engine.cs:137)
UniRx.Async.CompilerServices.MoveNextRunner
1:Run() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/MoveNextRunner.cs:20)
UniRx.Async.UniTaskCompletionSource:TryInvokeContinuation() (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:171)
UniRx.Async.UniTaskCompletionSource:TrySetResult() (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:189)
UniRx.Async.CompilerServices.AsyncUniTaskMethodBuilder:SetResult() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/AsyncUniTaskMethodBuilder.cs:81)
Naninovel.<PerformPostEngineInitializationTasks>d__92:MoveNext() (at Assets/Naninovel/Runtime/State/StateManager.cs:358)
UniRx.Async.CompilerServices.MoveNextRunner1:Run() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/MoveNextRunner.cs:20)
UniRx.Async.UniTaskCompletionSource:TryInvokeContinuation() (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:171)
UniRx.Async.UniTaskCompletionSource:TrySetResult() (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:189)
UniRx.Async.CompilerServices.AsyncUniTaskMethodBuilder:SetResult() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/AsyncUniTaskMethodBuilder.cs:81)
Naninovel.<<PerformPostEngineInitializationTasks>g__LoadGlobalAsync|92_1>d:MoveNext() (at Assets/Naninovel/Runtime/State/StateManager.cs:348)
UniRx.Async.CompilerServices.MoveNextRunner
1:Run() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/MoveNextRunner.cs:20)
UniRx.Async.UniTaskCompletionSource1:TryInvokeContinuation() (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:342)
UniRx.Async.UniTaskCompletionSource
1:TrySetResult(GlobalStateMap) (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:361)
UniRx.Async.CompilerServices.AsyncUniTaskMethodBuilder1:SetResult(GlobalStateMap) (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/AsyncUniTaskMethodBuilder.cs:229)
Naninovel.<LoadOrDefaultAsync>d__13:MoveNext() (at Assets/Naninovel/Runtime/Common/SaveSlotManager/IOSaveSlotManager.cs:104)
UniRx.Async.CompilerServices.MoveNextRunner
1:Run() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/MoveNextRunner.cs:20)
UniRx.Async.UniTaskCompletionSource1:TryInvokeContinuation() (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:342)
UniRx.Async.UniTaskCompletionSource
1:TrySetResult(GlobalStateMap) (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:361)
UniRx.Async.CompilerServices.AsyncUniTaskMethodBuilder1:SetResult(GlobalStateMap) (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/AsyncUniTaskMethodBuilder.cs:229)
Naninovel.<LoadAsync>d__12:MoveNext() (at Assets/Naninovel/Runtime/Common/SaveSlotManager/IOSaveSlotManager.cs:96)
UniRx.Async.CompilerServices.MoveNextRunner
1:Run() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/MoveNextRunner.cs:20)
UniRx.Async.UniTaskCompletionSource1:TryInvokeContinuation() (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:342)
UniRx.Async.UniTaskCompletionSource
1:TrySetResult(GlobalStateMap) (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:361)
UniRx.Async.CompilerServices.AsyncUniTaskMethodBuilder1:SetResult(GlobalStateMap) (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/AsyncUniTaskMethodBuilder.cs:229)
Naninovel.<DeserializeDataAsync>d__20:MoveNext() (at Assets/Naninovel/Runtime/Common/SaveSlotManager/IOSaveSlotManager.cs:158)
UniRx.Async.CompilerServices.MoveNextRunner
1:Run() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/MoveNextRunner.cs:20)
UniRx.Async.UniTaskCompletionSource1:TryInvokeContinuation() (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:342)
UniRx.Async.UniTaskCompletionSource
1:TrySetResult(String) (at Assets/Naninovel/Runtime/Common/Async/UniTask/UniTaskCompletionSource.cs:361)
UniRx.Async.CompilerServices.AsyncUniTaskMethodBuilder1:SetResult(String) (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/AsyncUniTaskMethodBuilder.cs:229)
Naninovel.<UnzipStringAsync>d__28:MoveNext() (at Assets/Naninovel/Runtime/Common/Utilities/StringUtils.cs:395)
UniRx.Async.CompilerServices.MoveNextRunner
1:Run() (at Assets/Naninovel/Runtime/Common/Async/UniTask/CompilerServices/MoveNextRunner.cs:20)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

Elringus
admin
Posts: 538
Joined: 11 May 2020 18:03

Re: Issue Regarding Custom UI

Post by Elringus »

You're probably spawning the gameobject with the custom UI before the engine is initialized. Make sure you don't manually add it on scene or as part of other prefabs (Naninovel will spawn it itself). Also, in case you're modifying engine initialization UI, don't use custom UI there, use plain uGUI.

tr5414
Posts: 3
Joined: 03 Jul 2021 23:51

Re: Issue Regarding Custom UI

Post by tr5414 »

Im not spawning the bar object in the scene beforehand, so thats not it. Im inheriting from the CustomUI class for this bar script.

Elringus
admin
Posts: 538
Joined: 11 May 2020 18:03

Re: Issue Regarding Custom UI

Post by Elringus »

Check UI example project, it has a custom UI set up and working fine.

Post Reply