0

Unity ver. 2019.4.19

Sorry for editing this question several time, I didn't use the term editor and edit mode correctly and I worte the code wrong. Now I've fixed.

I'm using timeline in my project. I made a custom clip like this to change some properties in matrial.

public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
    GameObject target = GetTargetGameObject();
    var renderers = target.GetComponentsInChildren<Renderer>();
    foreach (var r in renderers)
    {
        if (!Application.isPlaying)
        {
            foreach (var mat in r.sharedMaterials)
            {
                mat.SetFloat("_SomeProperty", SomeValueChangedByPlaytime(data));
            }
        }
        else
        {
            // in play mode use r.materials instead
        }
    }
}

I want to check the effects in timeline while I'm in edit mode, but I don't want to change my material assets by my code.

If I Use

r.sharedMaterials

This will change all matrial assets and this may cause some unexpected effect on unintended objects.

If I Use

r.materials

This will cause error "Instantiating material due to calling renderer.material during edit mode"

So how can I avoid changing matrial asset while still get correct preview in timeline edit mode?

0 Answers0