RenderSprite(in RenderParams, in SpriteParams, int, Matrix4x4)
Renders a sprite with the provided rendering parameters and sprite parameters.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
RenderSprite(RenderParams, SpriteParams, int, Matrix4x4)
public static void RenderSprite(in RenderParams renderParams, in SpriteParams spriteParams, int submeshIndex, Matrix4x4 objectToWorld)
Parameters
The index of a submesh Unity renders when the sprite contains multiple materials (submeshes). For a sprite with a single material, use value 0.
The transformation matrix Unity uses to transform the sprite from object space to world space.
Remarks
RenderSpriteUse to control sprite rendering programmatically without the need to create and manage GameObjects. submits the sprite for rendering, which means it doesn't render the sprite immediately. Unity renders the sprite as part of normal rendering process, and is compatible with SRP Batcher and GPU Instancing.
RenderSpriteRenderSpriteTo change the color of each sprite or use sprite mask interaction, use the SpriteParams parameter.
This method creates internal resources while the sprite is in the render queue. The allocation happens immediately and exists until the end of frame if the object is in the render queue for all cameras. Otherwise, the allocation exists until the specified camera finishes rendering.
The following example renders 10 Sprites with a given material:
Examples
using UnityEngine;public class ExampleClass : MonoBehaviour{ public Material material; public Sprite sprite; void Update() { RenderParams rp = new RenderParams(material); SpriteParams sp = new SpriteParams(sprite); for (int i = 0; i < 10; ++i) Graphics.RenderSprite(rp, sp, 0, Matrix4x4.Translate(new Vector3(-4.5f+i, 0.0f, 5.0f))); }}