- Home /
Why am I getting this error message on my iOS game when I change scenes?
Hi, I can't seem to figure out this error message. I would appreciate any help.
I am creating an iOS game and when the player walks into a trigger, it will transfer him to another level (scene). Each time I remotely play each level seporately, everything is fine but when I play from one level and trigger the change level trigger, I get this error message:
MissingReferenceException: The object of type 'GUITexture' 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.GUITexture.set_pixelInset (Rect value) Joystick.ResetJoystick () (at Assets/Standard Assets (Mobile)/Scripts/Joystick.js:97) Joystick.LatchedFinger (Int32 fingerId) (at Assets/Standard Assets (Mobile)/Scripts/Joystick.js:115) Joystick.Update () (at Assets/Standard Assets (Mobile)/Scripts/Joystick.js:183)
I am using the iOS first person controller for all my levels. In fact, I even made a prefab of the first person controller because I added a triggering sphere on it so that the players can change levels. Even when I used the "stock" first person controller, I still received the error. I did not change anything on any of the scripts of the mobile first person controller. The game works fine when I build it and install it on my iPhone. I just don't like having error messages.
Thanks for any help you may give.
Answer by PAEvenson · Feb 12, 2013 at 03:18 AM
I want to say the object is being accessed while the scene is trying to clean up and release everything. You can try waiting until the end of frame before you load the level.
public void ChangeLevel()
{
StartCorountine(WaitUntilEndOfFrameToLoadCoroutine("Next Level"));
}
public IEnumerator WaitUntilEndOfFrameToLoadCoroutine(string nextLevel)
{
yield return new WaitForEndOfFrame();
Application.LoadLevel(nextLevel);
}
Its a hack, but hey, it works.(Hopefully :P)
Highly unlikely to work - I'm not even sure its possible and I would not recommend the solution: it is both a hack and likely to have no effect.
I imagine his first person controller is resetting the position of the joystick thumb controls but that the thumb controls were deleted in the previous scene.
Well if you are calling DontDestroyOnLoad anywhere....look there first.
Or he needs to call DontDestroyOnLoad on the thumb graphics
It really depends on how your scenes are set up. I dislike using DontDestroyOnLoad because you need to manually destroy the objects later. Failing to destroy them could lead to duplicates when you load their initial scene again. There are multiple ways around this, but the only time I flag an object as DontDestroyOnLoad is when I manually instantiate an object in a script. This way I can check to see if one already exists before instantiating a new one.
I only ever use it for objects that persist for the lifetime of the game - any other use feels a bit fragile.
Answer by CoixdeNono · Feb 13, 2013 at 04:11 PM
I think if you try to create a gameobject kept on load, that is not destroyed between the scenes, and where you can put the function that is called between the scenes. Like here "The object of type 'GUITexture' has been destroyed but you are still trying to access it. "
Yes, I think everyone else has been saying this or a variation of it in the thread of comments below. Ideally $$anonymous$$ needs to upload his scenes somewhere so someone can point at the issue.
Your answer
Follow this Question
Related Questions
ERROR: Google play services on IOS 2 Answers
Splash Screen IOS CRASH. 0 Answers
XCode 4.6.3 iOs Build launch screen checkBytes issue 0 Answers
Calling Function in other Script via Touch => iOS Crash 1 Answer
GUITexture in Unity 5 0 Answers