Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

Graphics.RenderSprite

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static void RenderSprite(ref RenderParams renderParams, ref SpriteParams spriteParams, int submeshIndex, Matrix4x4 objectToWorld);

Parameters

Parameter Description
rparams The parameters Unity uses to render the sprite.
sparams The parameters that define the sprite.
submeshIndex The index of a submesh Unity renders when the sprite contains multiple materials (submeshes). For a sprite with a single material, use value 0.
objectToWorld The transformation matrix Unity uses to transform the sprite from object space to world space.

Description

Renders a sprite with the provided rendering parameters and sprite parameters.

RenderSprite renders a sprite for the current frame. This sprite is affected by 2D lights and sprite masks, but doesn't support shadows. All cameras can render the sprite, or a specific camera.

Use RenderSprite to control sprite rendering programmatically without the need to create and manage GameObjects. RenderSprite 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.

To 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:

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))); } }