GUISkin Null Reference Exception

So I’ve used the following code in Unity multiple times without a problem. However, when trying to use it in the iPhone(version 1.0.2f4) it always gives me a Null Reference Exception error. The error is received upon playing the game is always on the line where I cast the GUISkin variable.

Is there a different Syntax for casting the variable in the iPhone version of Unity?

The main purpose of this is to change the slider/scroll bar images of the GUISkin from the default Unity images. Any other alternative is much appreciated.

Also the GUISkin is assigned in the Inspector.

var gSkin : GUISkin = new GUISkin();

function OnGUI(){
   GUI.skin = gSkin;
}

Hi,
could you post NullReference exception stack trace?

Not entirely sure what you are asking but my best guess is this:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUISkin.OnValidate () (at /Users/build/builds/unity-iphone-1.0.2/iphone-1.0.2/Runtime/Export/Generated/GUIUtility.cs:976)
UnityEngine.GUISkin:.ctor()
TestFile:.ctor() (at Assets/Scripts/TestFile.js:1)

Also I know that you can specify a Horizontal and Vertical Scrollbar style using GUIStlye when declaring a BeginScrollView, but I don’t understand where I’m supposed to be placing the scrollbar image as well as the thumb image like you do in the GUISkin. Hince why I was using a GUISkin for that feature.

[/code]

Hi,
you are not supposed to create GUI skins via calling constructor from scripts. You need to create gui skin asset (with right mouse click in project view “Create->GUI skin”) and then select it for your gui skin variable in the inspector.

Anyway null reference exception does not look good, feel free to submit a bug report.

Is it generally good practice not to call the constructor in general in both Unity and Unity iPhone?

And I will submit the bug report right away.