0
\$\begingroup\$

I'd like to add a custom material to a line that I'm drawing in Unity (using Vectrosity). I'm using Unity's built-in "Unlit/Texture" shader. When I drag a texture from my Resources directory into the "Texture" slot in my shader, everything looks good:

Unity editor with texture selected

But when I click play, the texture disappears:

Unity editor with texture unselected

and my line doesn't show up in my game. However, if I drag the texture to the shader's texture slot after I click play, the texture seems to "stick" and my line renders as expected:

Line with texture applied

But once I stop and start the game, the texture again disappears.

Why is Unity kicking out my texture when my game starts? Is there something wrong with my texture? I don't see any warnings or errors in the console. I've tried with numerous different textures, and they all do the same thing.

I'm using Unity 5.6.1f1.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

It seems that some script is removing the texture from the material at runtime.

I suggest you check Awake, OnEnable and Start on your scripts, apart from an odd Unity bug, the culprit should be there somewhere.

You should search for a Material type variable, and then look if there's a materialVariableName.mainTexture = someValue;. When someValue is null, the material's texture is obviously reset.

Edit: I forgot, you should check for materialVariableName.SetTexture("_MainTex", someValue); too.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks, I think this was it. I changed how I was initializing my Vectrosity line, and now my material doesn't lose its texture on play. \$\endgroup\$ Commented Jun 18, 2017 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .