Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 problemecium · Aug 13, 2015 at 08:45 AM · shadermaterialproceduralshaderlabmodding

Material(string) is obsolete. How else can a shader be loaded at runtime?

For some time now I've been a fan and modder of a certain game which uses its own asset database similar to the one in the Unity editor - at the start, it loads all the models and textures in its directory and converts them into GameObjects, etc. so as to make the game expandable and mod-friendly.

Currently I have a mod written that uses a custom shader, which can be imported into the game using "Material(string)". However, recently when using this function in the Unity Editor, I've been presented with a message that Material(string) is "obsolete" and will be removed in the future. In the interest of not being blindsided when this happens, I'd like to know what alternate options there are for loading a shader at runtime like this. I've already looked over http://answers.unity3d.com/questions/987078/materialstring-is-obsolote.html and done some Google searches that took me to old webpages (February 2015 or earlier) that are no longer relevant.

The "obvious" solution as recommended in the editor and most places I've seen is to "use shader assets", but unless I myself am the developer of the game, I can't do that - and even if I were, I can't be expected to recompile the game for every user out there based on whether or not they want my mod.

So someone please tell me if there is some way to load shaders during game runtime, perhaps from text, from a compiled shader file I have created previously, or otherwise!

Or if not, can anyone confirm that when this function does get removed, the Unity team has plans to introduce a substitute?

Comment
Add comment · Show 7
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 sys12 · Sep 15, 2015 at 01:00 PM 0
Share

What's wrong with the solution in the url you attach? You can do exactly the same as that.

avatar image problemecium sys12 · Sep 15, 2015 at 11:04 PM 0
Share

I need to be able to load a shader AFTER the game has been compiled. The solutions in the linked thread all involve saving a file in the project folder, which means that when the game is compiled, the Unity Shader Compiler will compile it into the game. Adding a shader file to the folder after this point will not cause it to be compiled, and it will thus be inaccessible to Shader.Find().

avatar image sys12 problemecium · Sep 16, 2015 at 10:24 AM 0
Share

I think you've mentioned that there is a shader file created previously. Why don't you put that into your folder before compiling the game and load in during game runtime? I think all runtime support for shaders are removed after Unity 5.2.

But I guess you still can create a shader which takes some values at runtime to do what you want.

Show more comments
Show more comments

2 Replies

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

Answer by maccabbe · Sep 16, 2015 at 03:03 AM

You could try asset bundles. They would work as follows

  1. Package you shader into an asset bundle that will be part of your mod.

  2. Next, in your script, load the assetbundle from a file using www.LoadFromCacheOrDownload (it can be a file path or a web link).

  3. Finally get the shader from the assetbundle using AssetBundle.LoadAsset.

Not sure if the game you are trying to mod will support this and it would be tricky to support since you'd basically have to let modders write scripts. However any game that does support this would give modders an easy way to add any non script asset, from models and textures to materials, animations, and scenes.

Comment
Add comment · Show 1 · 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 problemecium · Nov 22, 2015 at 06:38 AM 0
Share

It took a while to get around to testing this approach (as it is a bit more involved than I'd expected and required me to get the hang of AssetBundles), but so far it does indeed work with no obvious problems. I suspect that AssetBundles are the new standard for importing custom content from now on.

avatar image
0

Answer by kumbayaco · Sep 15, 2015 at 12:41 PM

Shader sdr = Resources.Load ("Diffuse") ; renderer.sharedMaterial.shader = sdr;

"Diffuse" is the shader name, not the shader file name.

Comment
Add comment · Show 1 · 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 problemecium · Sep 15, 2015 at 11:05 PM 0
Share

This will work fine if I want to load the built-in "Diffuse" shader. What I need is to be able to compile the game, then add a new shader that isn't already included and create a material based on that.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Shader.SetGlobal for properties that materials already have 0 Answers

procedurally generated gradient 2 Answers

How to avoid Texture.Apply() 1 Answer

How do you hide a shader property? 2 Answers

Semitransparent shader not visible in front of objects 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