- Home /
Answer by Statement · Mar 28, 2011 at 12:54 PM
Use Resources.Load.
var GUISkin mySkin;
function Start() { mySkin = Resources.Load("MySkin"); }
function OnGUI() { GUI.skin = mySkin; // Rest of gui code. }
That doesn't work (at least not in Unity 3.5!). I get the warning "WARNING: Implicit downcast from 'UnityEngine.Object' to 'UnityEngine.GUISkin'."
And of course my guiskin doesn't load. Unity switches to the default skin, and of course doesn't find all my custom styles there.
Edit: Now I see what's happening. It's important to mention that whatever you load via the Resources.Load-command has to be in a project-folder calles "Resources". I wasn't aware of that (and it really is nonsense - how to organize my project should be my choice, and all project-resources should be accessible, no matter where they are.)
The "Implicit downcast" warning is just a warning. If you add "as GUISkin" behind the load function the warning should go away. You have placed your GUISkin in a Resource folder because those assets are always included into your project. All other assets are only included into your build when you reference them somewhere from a scene. If you don't use a texture, model, sound file it's not included in the build. That's why the usual approach is to assign your assets to public variables of a script.
The Resource folders are a nice feature, but you can easily loose the track of what's going into your game and what not.
Also for streamed builds like a webbuild i should mention that all assets from all resource folders are loaded at the start because Unity can't deter$$anonymous$$e when or where you're going to need them.
Your answer
![](https://koobas.hobune.stream/wayback/20220613115310im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUI Skin Custom textures in C# 2 Answers
Custom GUI Button is Black 1 Answer
Drawing Editor Inspector GUI based on selected/current prefab (CustomPropertyDrawer) 2 Answers
GUI Button selected changes color and stays until another button is clicked 1 Answer
Window Background Image not showing 1 Answer