NullreferenceException, BeginScrollView style change

Hi there Unity fokes, I am in need of a bit of help here. In a game project, we are trying to create a chat system, and for that chat system I have decided that it will be useful to use the Unity GUI.
In that case, we have programmed a chat window using GUI.BeginScrollView, so the player can scroll up and down in the chatbox.
When using BeginScrollView, you get two ‘not so nice’ scrollbars and my intention is to hide them, but no matter what I do, I can’t seem to remove them. I attempt to execute the BeginScrollView this way:

GUI.BeginScrollView(
                new Rect(0, 0, 220, 300), 
                scrollPosition, 
                new Rect(0, 0, 220, 350),
                false,
                false,
                chatSkin.horizontalScrollbar,
                chatSkin.verticalScrollbar
               );

Where chatSkin is a GUISkin. But by doing this, I get the following error:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUI.BeginScrollView (Rect position, Vector2 scrollPosition, Rect viewRect, Boolean alwaysShowHorizontal, Boolean alwaysShowVertical, UnityEngine.GUIStyle horizontalScrollbar, UnityEngine.GUIStyle verticalScrollbar, UnityEngine.GUIStyle background).

The following error disappears if I remove the two last arguments in the method call “chatSkin.horizontalScrollbar” and “chatSkin.verticalScrollbar”. The GUISkin chatSkin is defined in top of the script (haven’t copied that though). The mySkin GUISkin has been assigned in the inspector.

Taking into considerations its a NullreferenceException, I have been glancing in the Inspector of chatSkin, though no matter what I do, I can’t seem to get rid of this error.
I hope the community out there can help me. Here is the rest of the function, best regards - Marc Pilgaard

private void ChatWindow()
        {
            Vector2 scrollPosition = Vector2.zero;
            GUI.BeginGroup(new Rect(Screen.width/1.25f, Screen.height/1.25f - 300, 800, 600));
            string focusWindow = GUI.GetNameOfFocusedControl();
            GUI.BeginScrollView(
                new Rect(0, 0, 220, 300), 
                scrollPosition, 
                new Rect(0, 0, 220, 350),
                false,
                false,
                chatSkin.horizontalScrollbar,
                chatSkin.verticalScrollbar
               );
            
            GUI.Box(new Rect(0, 0, 220, 300), CurrentChat(""), chatSkin.box);
            GUI.EndScrollView();
            GUI.SetNextControlName("chatfield");
            stringToEdit = GUI.TextArea(new Rect(0, 302, 220, 50), stringToEdit, 200, chatSkin.textArea);
            GUI.EndGroup();

            if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Return && focusWindow == "chatfield")
            {
                GUIUtility.keyboardControl = 0;
                CurrentChat(stringToEdit);
                stringToEdit = "";
            }
            else if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Return && !(focusWindow == "chatfield"))
            {
                GUI.FocusControl("chatfield");
            }
        }

Here are my chatSkin settings from the inspector:
125chatSkin from inspector125

1252513-untitled-4.png125

Keep in mind that scrollbars needs several styles. That’s why it’s usually better to just switch the whole skin. Unity determines the other style names like this:

GUI.skin.GetStyle(style.name + "thumb")
GUI.skin.GetStyle(style.name + "upbutton")
GUI.skin.GetStyle(style.name + "downbutton")

// or those for the horizontal version:
GUI.skin.GetStyle(style.name + "leftbutton")
GUI.skin.GetStyle(style.name + "rightbutton")

where style is the style you’ve given. So you have to set your skin as the current and make sure you have the additional styles as well.

Can you check in the inspector your chatSkin - Horizontal Scrollbar - Normal - Background - a texture should have been assigned to it or if you see “missing texture” then you need to assign a texture to the background. Also check the same for Vertical Scrollbar.

http://docs.unity3d.com/Documentation/ScriptReference/GUI.BeginScrollView.html

try this:

GUI.skin = chatSkin;
GUI.BeginScrollView(
                new Rect(0, 0, 220, 300), 
                scrollPosition, 
                new Rect(0, 0, 220, 350),
                false,
                false
               );

it will accomplish the same thing