2D Side Scroller Exceptions

Hi Guys,

I am currently trying to get to grips with Unity by creating a simple little 2D scroller for Android.
The Character Controller I am using is the “2D Side Scroller” Prefab in the Mobile Standard Assets which I can get working well. However when I Load the next level using Application.LoadLevel and move onto the next Scene (which has the same controller prefab) every time I hit one of the touchpads there is an error in the console which reads :-

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)

It doesn’t stop the touchpads or the game working however the console window obviously fills up rather quickly with all these errors.
Is this something any of you have come across before and solved or if anyone could hazard at a solution I would be grateful.

Also when I start on any of the levels there are no errors.

Thanks,

Ian

I think I have fixed it myself…

In the Joystick script I wrapped the gui references in the “ResetJoystick()” function in an if statement to say

function ResetJoystick()
{
   if(gui != null){
      gui.pixelInset = defaultRect;
      if(touchPad)
         gui.color.a = 0.025;
   }

   lastFingerId = -1;
   position = Vector2.zero;
   fingerDownPos = Vector2.zero;
}

This seems to have stopped the exceptions appearing and also keep the desired functionality of the touchpads :smile:

Hope this helps anyone else that may come across this issue.

Do you have Unity - Scripting API: Object.DontDestroyOnLoad in your script?

It is not in the script, I have been using one of the scripts that came standard with Unity 4.2.2 Mobile Assets, Joystick.js in the “2D Side Scroller” prefab but I am starting to see more and more that most need to be altered in some way to suit your own needs :slight_smile:

Also to be honest I am not entirely sure how I would adapt the Joystick.js to use the DontDestoryOnLoad method. I will maybe play around with it a bit once I get my head round some of the other bits and pieces.