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
3
Question by rFinster · Feb 04, 2015 at 03:13 PM · shaderruntimeexceptionobjmodelimporter

Why does my Unity application can't find the Specular shader after build at runtime?

Solved this by my own in the meanhile (see Update 3 at the bottom). But maybe it's helpful for any Googling Googler, so I'm not going to delete. (though this post is not even released by moderation right now lol)

System-informtions:
HP ProBook 450 G0 (Intel Core i5)
Windows 8.1 64 bit
Unity 4.6.1f1 (free version)
Application built as standalone Windows player

Hint:
(For some reasons, like integrated Occulus SDK, I didn't use my original project for debugging and those screenshots, but the example scene from the author of that obj-loader mentioned later)

Description of my problem:
My purpose was to make Unity to load a .obj 3D model at runtime into my world. For this I used a parser I found at everyday3d.com.
So ... everything seemed to work fine, I put that scripts into my project and was able to load obj files from my webspace, I even managed to add dynamicaly loaded behaviour from outside. Well so the model gets visible within the test environment of the Unity Editor:

But when I build it and start the application, the model doesn't appear at runtime. What I get during debugging the development build is the exception visible in the screenshot:

As far as I can reproduce, the problems begin with

 m = new Material(Shader.Find("Specular"));

And yeah well ... I have no clue what happens afterwards. The "Build Agent" directory doesn't exist, when I try to inspect the further "path" of the given exception. I guess that's just some temporary help-code for the Unity interpreter? Anyway my applications seem to not find the Specular shader. I hope someone can help me :/

Update: Hm found something in the output_log.txt of my project (data folder). Can't get something new out of it but maybe you can:

 NullReferenceException
 at (wrapper managed-to-native) UnityEngine.Material:Internal_CreateWithShader (UnityEngine.Material,UnityEngine.Shader)  
 at UnityEngine.Material..ctor (UnityEngine.Shader shader) [0x00006] in C:\BuildAgent\work\d63dfc6385190b60\artifacts\StandalonePlayerGenerated\ShaderBindings.cs:149   
 at OBJ.GetMaterial (.MaterialData md) [0x0000c] in D:\Source\Unity_test4_whereIsMyMonkey\Assets\OBJ\src\OBJ.cs:209   
 at OBJ.Build () [0x0002a] in D:\Source\Unity_test4_whereIsMyMonkey\Assets\OBJ\src\OBJ.cs:236   
 at OBJ+c__Iterator0.MoveNext () [0x001e2] in D:\Source\Unity_test4_whereIsMyMonkey\Assets\OBJ\src\OBJ.cs:73 


Update 2: According to information inside the Unity Scripting Documentation, Shaders will only be included into the build, if they were used otherwise in any scene or are stored in the Resources directory. So the next question: where are the standard shaders of unity located? Seems like I have to push them into the Resources folder.

Update 3: Ok, this has been the right clue. Quick workaround: added a new material using the Specular shader into a folder named Resources. Thanks for your attention, anyway!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MazonDel · Jan 28, 2019 at 10:40 AM

I had a similar problem to this and an easier/simpler way to solve the issue is the following.

Go to Edit->Project Settings->Graphics.

In this space find the "Always Included Shaders", extend the list by 1 slot and in the new slot select the shader you need. This will force Unity to always build that shader into the build.

Hope this helps!

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
avatar image
0

Answer by LFCB · Oct 13, 2017 at 12:32 AM

Dude that is an excellent info, I was in the same situation but your post saved me. Thank you very much :D

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
avatar image
0

Answer by rccohn · Nov 01, 2020 at 05:29 PM

Hi @MazonDel and @rFinster -

This is a great and helpful post. I ran into the same problem (worked OK in the editor, ran into the exception very much like the one above when running the built app).

By extending the shader list with the one I was using, and saving into an Assets/Resources folder, that seemed to fixed the problem. Note that I wasn't sure where to do the assets save when making the change in the Project Settings ... | Graphics tab, and there was no guidance from the save dialog as to where it should be saved. I accepted the default name: NewShaderVariants.shadervariants.

So, I would say that all of the above at least pointed me in the right direction of how to solve the problem.

Thanks again.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GameObject not receiving shadows 0 Answers

Material from .obj not being imported in Android App 0 Answers

Getting "vertexSize != stride" when using mesh tangents 1 Answer

How to fix a object intersection problem? 0 Answers

Null shader on camera at runtime? 3 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