Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by ratchet2324 · Jun 28, 2017 at 07:28 AM · scripting problemmaterialskybox

Creating Material from String (Unity 5.6)

Hi all,

I am trying to create a material using a string which is now obsolete. I have the following code currently but I receive an error (following code) and I am unsure how to fix it.

 private string skyMat;
 skyMat = PlayerPrefs.GetString("skybox");
 RenderSettings.skybox = new Material(Application.dataPath + "/Resources/Skyboxes/" + skyMat + ".mat");

Error:

Trying to create a material from string - this is no longer supported. UnityEngine.Material:.ctor(String)

What I want to do is to find the material which is a string saved to PlayerPrefs and set the skybox to it. Also I'm not sure how to set skyboxes up nowadays. Is it still RenderSettings.skybox?

Thanks in advance,

Cordel

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

1 Reply

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

Answer by Trevdevs · Jun 28, 2017 at 07:49 AM

Sorry but there is no way to do this anymore, and quite honestly thankfully it is gone.

Simplest thing to do now would just be

 public Material skyboxMaterial; //Assign in inspector
 
     void Start()
     {
         RenderSettings.skybox = skyboxMaterial;
     }
Comment
Add comment · Show 3 · 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 ratchet2324 · Jun 28, 2017 at 08:08 AM 0
Share

That's a bummer, because all of my levels have randomly generated skyboxes and so when the level is completed, it would make sense to have the same skybox as the level, which is why I saved the name of it to the PlayerPrefs to reload it in the LC scene.

avatar image Trevdevs ratchet2324 · Jun 28, 2017 at 06:38 PM 0
Share

What you could do is create an array of $$anonymous$$aterials and do a Random.Range on an int to select one of the skyboxes at random.

 public $$anonymous$$aterial[] skybox$$anonymous$$aterials; //Still all assigned in the inspector
 
 void Start()
 {
     int randomInt = Random.Range(0, skybox$$anonymous$$aterials.Count + 1  );
     RenderSettings.skybox = skybox$$anonymous$$aterials[randomInt];
 }
avatar image ratchet2324 Trevdevs · Jun 28, 2017 at 11:15 PM 0
Share

Thanks mate. Just re-worked it to have an object with a separate script with a DontDestroyOnLoad to keep an array of skyboxes and just allocate the number to it each time.

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

114 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I get rid of the black line in Unity Sky 1 Answer

Need Help with changing skyboxes -1 Answers

Can't apply Skybox material to Skybox type variable 1 Answer

How to change the reflection according to skybox-material? 2 Answers

Skybox is reflecting from game object in some devices? 0 Answers


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