Using 2018.3.0f2. I’m trying to assign a unique material to DecalProjctorComponent at runtime. The goal is to have multiple projectors each have it’s own instance of a material so that the projectors aren’t sharing the same material. I’m animating the texture so I need to have each projector’s texture separately controllable.
The results of creating a new material using either a material or calling a shader “HDRenderPipeline/Decal” have resulted in the projctor showing nothing. The material property looks fine in the inspector, just not showing in game. The same projector having its material property linked directly to the original material works fine.
Creation using original material:
material = new Material(baseMaterial);
decal.m_Material = material;
Or using shader:
material = new Material(Shader.Find(“HDRenderPipeline/Decal”);
material.CopyPropertiesFromMaterial(baseMaterial);
decal.m_Material = material;
Has anyone had success using a material instantiated in code? Or perhaps knows another system that might work?
I should include the update loop where the texture is updated. It uses a RenderTexture to capture output from a camera.
void Update()
{
RenderTexture.active = renderTexture;
texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
RenderTexture.active = null;
texture.Apply();
material.SetTexture(“_BaseColorMap”, texture);
}
This definitely seems to be a bug. Tried with latest Unity 2018.3.6 and HDRP 4.9.0. I made a simple project exhibiting the issue. I notice that after I update the material in code and then click on a control for the projector in the editor (such as Crop Decal with Gizmo) then the projector updates and displays correctly.
What’s the preferred method for feedback to Unity since this is an experimental feature? Bug report? Posting in the feedback thread for HDRP?
Hi ! Thanks for reporting.
Both reporting method are valid, as the package is publicly available, and this thread by itself is enough, no need to double post in the feedback one.
This issue seems easilly reproductible, so if you have time to do a repro-project and send a bug report it would be nice, else a dev coming through here (I’ll poke them) can do it when he has enough time.
Thanks. I went ahead and submitted a bug report as I had a sample project that demonstrates the behavior.