#Renderer.GetMaterials outputs a null list (except after compiling with domain reloading disabled?)

1 messages · Page 1 of 1 (latest)

vocal zenith
#
    void OnDestroy()
    {
        rendererWithMaterials.GetMaterials(allInstantiatedMaterials);
        Debug.Log($"{allInstantiatedMaterials}");
        foreach (Material material in allInstantiatedMaterials)
        {
            Debug.Log($"destroying {material}");
            Destroy(material);
        }
    }

This method causes the error

ArgumentNullException: m
Parameter name: The result material list cannot be null.
UnityEngine.Renderer.GetMaterials (System.Collections.Generic.List`1[T] m) (at <25ce29052dfe4e49a635a42f7798806b>:0)
LightObjectVisuals.OnDestroy () (at Assets/Scripts/Effects/LightObjectVisuals.cs:38)

Line 38 is the GetMaterials one

#

The materials are being modified correctly, and strangely to me after compiling the script but with domain reloading disabled it works just as I expect it to just once
(Unity 6.0.58f2)

#

Chances are I might just be using the List wrong somehow

zinc rune
#

allInstansiatedMaterials is null

#

i believe you want a non null empty one to pass into that

vocal zenith
zinc rune
#

unless that doesn't end up working I'm gonna say yes 😄