Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Need SetSharedMaterials/SetMaterials methods on Renderers to avoid allocations

Discussion in 'General Graphics' started by Prodigga, Nov 23, 2018.

  1. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    785
    Hi there

    There is a GetMaterials and GetSharedMaterials method which lets you pass in your own List<Material> so that you can avoid allocating garbage when fetching the material list on a Renderer.

    But without a SetMaterials and SetSharedMaterials method, this is useless because we need to convert this list to an array if we ever want to alter the materials on a renderer. The only way to set the materials is via 'renderer.sharedMaterials' or 'renderer.materials' setters, which both take arrays.
     
    pointcache likes this.
  2. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    525
    Agree should at least have a variant with NoAllocHelpers.ExtractArrayFromList(values)
     
  3. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    785
    Why do I feel like this is going to be one of those "advanced features" don't won't gain enough traction with the community to ever get implemented? :p Hopefully a Dev can respond here directly to give me some hope !