Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Companion components SpriteRender how to access it and change the texture?

Discussion in 'Graphics for ECS' started by UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23, Sep 10, 2023.

  1. UDN_41c53a1a-0daa-4677-a552-0a2e49c9be23


    Dec 28, 2016
    When bake a SpriteRender, how to change the sprite ?
    i see the Companion components SpriteRender in the runtime , and clone 3 times?

    i know how to use [materilproperty""] to change color and other property by shadergraph,
    but how to change the texture, because the texture can be null , so the struct can't use.
    i can use RenderMeshArray to change the texture before the entity to Instantiate. just like
    Code (CSharp):
    1. Material M1 = new Material(ShareMateril);
    2. M1.SetTexture("_Texture2D", s1);
    3. var desc = new RenderMeshDescription(shadowCastingMode: ShadowCastingMode.Off, receiveShadows: false);
    4.                 var renderMeshArray = new RenderMeshArray(
    5.                     new Material[] { M1 },
    6.                     new Mesh[] { ShareMesh }
    7.                     );
    8.                 RenderMeshUtility.AddComponents(
    9.                         config.EntityPrefabs,
    10.                         state.EntityManager,
    11.                         desc,
    12.                         renderMeshArray,
    13.                         MaterialMeshInfo.FromRenderMeshArrayIndices(0, 0));
    but i just want to know hot to access the spriterender ,because in the runtime the Companion components still in the inspector.