Materials loosing textures

Hi there…

I’ve been having some problems with this.

I have a couple of objects which have a material and a texture applied to it within Unity.

I’m replacing, during run-time though scripting, in authoring mode (inside Unity), a couple of material’s main textures from files I’m opening with WWW.

When I press stop, most of the times (I could not learn any pattern to this) the materials do not get their original main texture back. They keep the shader though.

If I press play again, the textures get correctly loaded, so there’s no problem on that part. But, when I press stop, I have to re-apply all the textures to each object in order to work in Unity.

As far as I understand, this would be the intended effect of working with Renderer.sharedMaterial, and not with the Renderer.material.

Any thoughts on how to solve this or what might be happening?

Thanks,

Nicolas.

It’s interesting to add that this only happens when replacing textures.

I use the same method to replace videos (WWW.movie) and sounds (WWW.audioClip) through scripting.

But both videos and sounds, always, when I press stop go back to the stored videos and sounds from the projects.

Are you actually modifying the textures (ie, with Texture2D.SetPixels)? If you change a texture created from an asset, it will actually modify the asset.

No, I am not.

I’m just replacing the material’s mainTexture with a WWW.texture object downloaded.