[About macOS Sequoia] (Updated October 22, 2024)
Live2D Cubism Editor 5.1.02 now supports macOS Sequoia.
Other Live2D Cubism products currently released are not guaranteed to work on macOS Sequoia.
Please refrain from upgrading macOS, as it may not operate properly.
Switching scenes: MissingReferenceException
Hi everyone!
I'm displaying my model in Unity without any problems.
Now I want to change from my scene with the model to another scene which has an options menu. Switching to the options scene works fine but when I switch back and try to move the model, I get the following error:
MissingReferenceException: The object of type 'Transform' 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.Transform.TransformPoint (Vector3 position) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineTransformBindings.gen.cs:378)
LAppView.UpdateTouchPos_2DCamera (Vector3 inputPos) (at Assets/Scripts/sample/LAppView.cs:305)
LAppView.TouchesBegan (Vector3 inputPos) (at Assets/Scripts/sample/LAppView.cs:83)
LAppModel.TouchesBegan (Vector3 inputPos) (at Assets/Scripts/sample/LAppModel.cs:607)
LAppLive2DManager.TouchesBegan (Vector3 inputPos) (at Assets/Scripts/sample/LAppLive2DManager.cs:126)
MyGameController.Update () (at Assets/Scripts/sample/MyGameController.cs:369)
0 ·
Comments
Sorry that it took a few days to answer.
How are you switching between scenes? Are you using the 'SceneManager' functionality Unity provides?
I'm using the 'SceneManager' class (
SceneManager.LoadScene ("NewSceneName");
)This error is the same as the following thread .
Japanese Live2D Forum - SampleApp1でScene切り替え
I think that to solve in LAppView Modify .
Good Luck!
Hey, thanks for posting a link to the solution !
@Nyanko
Could you try out naotaro's suggestion? (Just add a null check). Let us know how that worked out .
Thank you, that fixed the exception. I can move the model with my finger und play expressions without a problem after changing the scene back.
But for some reason when I try to access
LAppModel model
inLAppModelProxy
it throws a MissingReferenceException: I try to call a CoRoutine that accesses the model and that is working fine before the scene change.It looks like the
LAppModelProxy
is destroyed when switching scenes and not created again when loading the scene with the model in it.Sorry. I thought I'd already answered you but I just noticed I forgot to push the "Post Coment" button last week...
Could you check whether the GameObject the LAppModelProxy component is attached to "survives" the scene switch? Or whether it is recreated? (Or whether it doesn't exist at all)?
It seems like the GameObject with the LAppModelProxy component gets destroyed in scene switch and gets recreated when returning to the previous scene.
The Awake() method with CreateModel() is called each time.
If that doesn't work, things get a little bit hacky because while the lifecycle of the LAppModelProxy is controlled by Unity the LAppModel lifecycle is not... (This design will change in the next major version of the SDK, though).
I looked into 'LoadSceneMode.Additive', but when I do that the "old" scene with the model is overlapping my new scene. I tried to figure out how to solve that but I couldn't find anything...
I'm doing the following in the Start() method of my script:
DontDestroyOnLoad(GameObject.Find("Canvas_Model"));
"Canvas_Model" is a Canvas that holds only the model.
When I'm now switching scenes and return to the scene with my model, "Canvas_Model" gets created again so now I have now two models in my scene.
Do I miss there something with DontDestroyOnLoad()?
Is there any eta for the next major version of the SDK to make this more simple?