Search Issue Tracker

Fixed in 2018.2.X

Votes

2

Found in

2017.1.0b6

Issue ID

916541

Regression

No

[Material] - 2017.1 : Material reference appears to be missing on the HoloLens when changing the material color by script

Graphics - General

-

I was investigating a forum post about a user not being able to change the color of a cube via script. When I launched the app to the hololens, the cube would appear with a pink texture almost as if the material reference was missing. The cube does change color when using remoting or simulation in holographic emulation window.

Notes:
Forum Post : https://forum.unity3d.com/threads/hololens-changing-color-of-primitive.473491/#post-3089016
RS2
Script code causing the issue : cube.GetComponent<Renderer>().material.color = new Color(0,1,0,1);

Platforms reproduced:
HoloLens
Oculus
Open VR
UWP standalone
PC Standalone

Version 2017.1.0b6 (38ec4e48ade7)
Tue, 16 May 2017 23:34:37 GMT
Branch: 2017.1/staging

Repro Steps:
1.) Download the project
2.) Build and Deploy to the HoloLens

Actual:
Changing the cubes color via script causes an error with the material

Comments (2)

  1. tengel

    Jan 04, 2018 15:26

    Indeed, it may not be included in standalone. However, if the Shader.Find is unable to locate the desired shader, it should report an error or the pink "missing shader" (which does not always happen).

    I had a similar issue (objects not being rendered on build - using DrawMesh), I used Shader.Find to create a new material at some point. It seemed natural to me that the shader would be included (since the same shader was used in other objects), and since neither material nor shader was null (and no error reported) I assumed everything was ok with the material. However, the problem persisted (though no pink material or error reported). In this case I chased the issue in a hole different direction since it appeared that Unity was able to successfully find the shader. I even hooked up RenderDoc to find out that the draw calls were not even sent to GPU (which its also weird).

    It took me a couple of hours to find out (in trial-and-error style) to finally discover that if I used an explicit reference to the material, it would work.

    Long story short. There should be a better handling when Unity is unable to find the shader. Perhaps report a warning or error - even null would do. I was surprised (and disappointed) to find out that the shader was not found and, at the same time, it wasn't null (which doesn't make any sense to me) and no error was reported.

    I made a quick demo to illustrate the issue. In this case, since there is an object in the scene and a material in the resources using the standard shader, Shader.Find("Standard") should work (I believe). However, the results from the editor and standalone are different, since the cubes are not drawn at all on standalone. https://www.dropbox.com/s/1e8488a2y9zah08/DynamicMaterialBug.rar?dl=0

  2. acshearer

    Jun 07, 2017 17:21

    The shader in the material reference indeed does not exist, as it is not included in the project. This appears to be by design.

    From https://docs.unity3d.com/ScriptReference/Shader.Find.html:
    Note that a shader might be not included into the player build if nothing references it! In that case, Shader.Find will work only in the editor, and will result in pink "missing shader" materials in the player build. Because of that, it is advisable to use shader references instead of finding them by name. To make sure a shader is included into the game build, do either of: 1) reference it from some of the materials used in your scene, 2) add it under "Always Included Shaders" list in ProjectSettings/Graphics or 3) put shader or something that references it (e.g. a Material) into a "Resources" folder.

    My problem resolved itself when I put the 'Standard' shader I was using in Assets/Resources.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.