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
5
Question by nikroth · Jan 09, 2014 at 10:52 AM · c#shadermaterialbuildingfind

C# Shader.Find not working

I am writing in C#. My project is running perfectly in the builder but after i build it for PC i tells me nullreferenceexception. i commented all my code little by little and i found that the problem line is this one:

Material myMat = new Material(Shader.Find("Transparent/Diffuse")); (in the update method)

the script was in the Assets folder, i tried moving it to Standard Assents and still doesnt work.

I think that my scripts are in the wrong place or there is some building option that i don't know of.. But it is extremely strage that in the builder when i click the play button there is no problem.... no matter where i place the scripts and other things...

Any advice will be tested and appreciated :)

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
4
Best Answer

Answer by GameVortex · Jan 09, 2014 at 11:52 AM

I am not sure, but it might be that because Unity does not include assets in the build that you have not reference directly it has stripped out the Transparent/Diffuse shader. So the Shader.Find function can not find it. Try making a new material in your assets folder that has the Transparent/Diffuse shader on it, assign this material in the inspector to a public material variable in your script. Then you can make a new material in your update method by copying the referenced one.

Something like this:

Declare and assign a Meterial variable:

 public Material material;

Then copy it when you want to create a new Material.

 Material myMat = new Material(material);
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 GameVortex · Jan 09, 2014 at 01:45 PM 3
Share

Also I forgot about this one: A somewhat better way is to edit Grahpic settings where you can add the Shaders you want the build to include no matter what. Go to Edit - Project Setting - Graphics. Increase the number by one and press the little circle on the right to bring up a list of all shaders. Select the on you want and it will be included in the build.

avatar image
2

Answer by Kolodej · Jan 09, 2014 at 02:46 PM

When the shader/material is not attached to any of the scene objects, then is not considered for compilation (i.e. works only in editor). There are 2 ways how to resolve the problem: 1. Move the shader to Resources directory. 2. Attach the maretial to some scene object.

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

20 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

Related Questions

Cannot change material on build 1 Answer

UI Text - changing material instance 1 Answer

Unity Normal Problem Between Two Seperated Model 1 Answer

How do you make an X-ray vision following the mouse? 1 Answer

[SOLVED] How can I modify the shader from the material of a single GameObject instead of all that are using the same material? 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