Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Richard 3 · Mar 28, 2011 at 12:44 PM · guicustomattachskinprivate

Attach a GUI Skin Dynamicaly

How can I attach a GUI Skin with Code. I only call my code during game play so I cant attach the skin in the inspector.

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

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. }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Forrest_Gimp · Feb 08, 2013 at 08:44 AM 0
Share

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.)

avatar image Bunny83 · Feb 08, 2013 at 09:17 AM 0
Share

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.

avatar image
0

Answer by Uzquiano · Mar 28, 2011 at 01:30 PM

Here you are ;)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges