Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

If you have any questions, reports, suggestions, or requests about Live2D, please send them to this forum.
※We cannot guarantee statements or answers from Live2D staff. Thank you for your understanding in advance.
Live2D Cubism
Cubism Products and Downloads
Cubism product manuals and tutorials
Cubism Editor Manual    Cubism Editor Tutorial    Cubism SDK Manual    Cubism SDK Tutorial
Cubism Editor 5.1.00 beta1 is now available!

We have incorporated some of the feedback we received from those who tried the alpha version.
Thank you very much for your comments and requests!
All alpha versions will soon be closed to the public and will no longer be available.
Also, the Cubism Editor 5.1 alpha category will be closed, so please send your comments and requests to the Cubism Editor category.

Switching scenes: MissingReferenceException

edited December 2023 in Help
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)


  • Options

    Sorry that it took a few days to answer.
    How are you switching between scenes? Are you using the 'SceneManager' functionality Unity provides?
  • Options
    Hi, thank you for the reply and no problem!

    I'm using the 'SceneManager' class (SceneManager.LoadScene ("NewSceneName");)
  • Options
    You use SceneManager.Load.Scene() once to switch to the menu and then once more to switch back, right?
  • Options
    edited May 2016
    This error is the same as the following thread .

    Japanese Live2D Forum - SampleApp1でScene切り替え

    I think that to solve in LAppView Modify .
    Good Luck!
  • Options
    Hey, thanks for posting a link to the solution :D !

    Could you try out naotaro's suggestion? (Just add a null check). Let us know how that worked out ;) .
  • Options
    @andi.g@live2d @naotaro

    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 in LAppModelProxy it throws a MissingReferenceException:
    MissingReferenceException: The object of type 'LAppModelProxy' 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.MonoBehaviour.StartCoroutine (IEnumerator routine) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineMonoBehaviourBindings.gen.cs:60)
    LAppModelProxy.SayCurrentTime () (at Assets/Scripts/sample/LAppModelProxy.cs:370)
    MyGameController.OnTimeTouched () (at Assets/Scripts/sample/MyGameController.cs:138)
    UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:144)
    UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:621)
    UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:756)
    UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)
    UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
    UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
    UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)
    UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
    I try to call a CoRoutine that accesses the model and that is working fine before the scene change.
  • Options
    Any input on that?

    It looks like the LAppModelProxy is destroyed when switching scenes and not created again when loading the scene with the model in it.
  • Options

    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)?
  • Options

    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.
  • Options
    In case you're loading the menu scene with the mode 'LoadSceneMode.Single' could you try to change the mode to 'LoadSceneMode.Additive' and manually set it active? This should basically allow you to 'overlay' your game scene with the menu scene preventing the game scene from being unloaded (and objects in that scene from being destroyed). This should make the most sense Unity-wise. Could you try that out?
    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).
  • Options

    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... :/
  • Options
    Ah, I see. Currently the simplest solution, which isn't clean at all, would be the following, I guess: Make the Live2D models survive the scene change (either by loading the menu scene additive or by preventing the model game object from getting destroyed when you switch scenes)). Then hide the model away (and anything else if required)...
  • Options

    I'm doing the following in the Start() method of my script:


    "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()?
  • Options
    Ok, I made it work with scene additive but it was quite messy.

    Is there any eta for the next major version of the SDK to make this more simple? :)
Sign In or Register to comment.