Unity 2022.3.5f1 URP 14
Gosh, I hate having to make a forum post, but I can’t figure this out. I am trying to manually cross fade objects (no LODGroup component). Here is the code I am using:
using Unity.Mathematics;
using UnityEngine;
public class manual_cross_fade : MonoBehaviour
{
public float4 fade;
MeshRenderer renderer;
MeshFilter filter;
void Start()
{
renderer = gameObject.GetComponent<MeshRenderer>();
filter = gameObject.GetComponent<MeshFilter>();
renderer.sharedMaterial = Instantiate(renderer.sharedMaterial);
renderer.sharedMaterial.EnableKeyword("LOD_FADE_CROSSFADE");
}
void Update()
{
renderer.sharedMaterial.SetVector("unity_LODFade", fade);
// renderer.forceRenderingOff = false;
// var cmd = CommandBufferPool.Get();
// cmd.Clear();
// cmd.DrawRenderer(renderer, mat);
// Graphics.ExecuteCommandBuffer(cmd);
// CommandBufferPool.Release(cmd);
// Graphics.DrawMesh(filter.sharedMesh, Matrix4x4.identity, mat, 0);
// var mpb = new MaterialPropertyBlock();
// mpb.SetVector("unity_LODFade", math.float4(fade));
// renderer.SetPropertyBlock(mpb);
}
}
But none of those work. When I debug using “Frame Debugger” the “unity_LODFade” never changes. I think it is getting overridden down the line.
The other solution would be to reinvent the wheel and manually cross fade in the shader etc. But I don’t want to do that.
Or maybe built-in “unity_” prefixed vars aren’t meant to get modified? Is this a bug?