Dear Users,

Now, we are seeking users who can give us a hand with expertise to evolve our software more dynamically.
If you are willing to help us, we’d like you to make a registration for “Live2D Creators Circle” via the link below.
Designers, programmers, translators are especially welcomed so far.
(More detailed explanation will be given to you before we ask you to do tasks)

https://docs.google.com/forms/d/1G5KK_GL3ozwPXtTHrpi_ktbsI8UZf8jlYRSlDworyBo/viewform?usp=send_form

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)

Comments

  • @Nyanko


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

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

    Japanese Live2D Forum - SampleApp1でScene切り替え

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


    @Nyanko
    Could you try out naotaro's suggestion? (Just add a null check). Let us know how that worked out ;) .
  • @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)
    UnityEngine.EventSystems.EventSystem:Update()
    I try to call a CoRoutine that accesses the model and that is working fine before the scene change.
  • 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.
  • @Nyanko

    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)?
  • @andi.g@live2d

    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.
  • 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).
  • @andi.g@live2d

    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... :/
  • 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)...
  • @andi.g@live2d

    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()?
  • 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.