Home > Software design >  How to change scene based on button click using Unity and MRTK?
How to change scene based on button click using Unity and MRTK?

Time:10-14

I'm trying to implement a menu with some buttons in order to load different scenes based on the clicked button.

What I've tried
I created a total of 3 scenes : menu, main and secondary. The menu scene contains the buttons. On the first button I added Interactable, NearInteractionTouchable and LoadContentScene. I then selected the desired scene to load in LoadContentScene and added an OnClick event to the Interactable script which triggers LoadContentScene.LoadContent. you can see it there

The problem
Now when I click on my button, the next scene isn't loading and I have those error messages in my Unity console :

Unable to find ISceneTransitionService service. NullReferenceException: Object reference not set to an instance of an object Microsoft.MixedReality.Toolkit.Extensions.SceneTransitions.LoadContentScene.LoadContent () ...

What did I do wrong ? I tried to find some solutions in the documentation or online but I couldn't find any tutorials

CodePudding user response:

From the error message you are trying to use the Scene transition service, please check if this service is registered in MixedRealityToolkit->Extensions. To clarify, for scene loading, this service is not necessary, if you don't know what it does, you can disable the corresponding code.

Also, you can refer Scene system content loading - MRTK 2 | Microsoft Learn and this official sample - OpenXR-Unity-MixedReality-Samples/BasicSample at main · microsoft/OpenXR-Unity-MixedReality-Samples · GitHub.

  • Related