- Home /
MissingComponentException Warning
IEnumerator ChildDissolve(float endValue, float duration)
{
float time = 0;
float startValue = _ChildDissolveValue;
while (time < duration)
{
int children = transform.childCount; // Getting Child material from MeshRenderer.
for (int i = 0; i < children; i++)
{
GameObject _CurrentChild = transform.GetChild(i).gameObject;
for (int j = 0; j < children; j++)
{
//if (_CurrentChild.GetComponent<MeshRenderer>() != null) // some child materials do not use a mesh renderer component.
{
// Code A doesnt work inside this check! (Creates extreme performance issues)
//Material _ChildMaterial = _CurrentChild.GetComponent<MeshRenderer>().material;
//float _ChildDissolveValue = _ChildMaterial.GetFloat("Dissolve"); // Variable I need.
}
// Code A: only working outside of statement. (122-123)
Material _ChildMaterial = _CurrentChild.GetComponent<MeshRenderer>().material;
float _ChildDissolveValue = _ChildMaterial.GetFloat("Dissolve"); // Variable I need.
_ChildMaterial.SetFloat("Dissolve", (Mathf.Lerp(startValue, endValue, time / duration)));
}
}
time += Time.deltaTime;
yield return null;
}
_ChildMaterial.SetFloat("Dissolve", endValue);
}
The line:
_ChildMaterial.SetFloat("Dissolve", (Mathf.Lerp(startValue, endValue, time / duration)));
This is giving me errors I've tried to write a null component exception if the current child is missing a MeshRenderer component and stick the code inside it. But not only does it break game functionality, the performance is not acceptable!
How could one check to see if a MeshRenderer has the "Dissolve" float? The code works as is, I just can't seem to resolve this console warning.
image-2021-06-03-154806.png
(61.6 kB)
Comment