Frequently asked questions | 2D Entities | 0.31.0-preview.3
docs.unity3d.com
    Show / Hide Table of Contents

    Frequently asked questions

    Getting started with Tiny

    To begin learning about DOTs, refer to the Entities Component System (ECS) online documentation for general information about DOTs development. Then join the Project Tiny forum for active discussion with fellow users and developers. With every release of Project Tiny, developers share demo projects that showcase how they can be built using Project Tiny.

    Assemblies contained in the package

    Unity.2D.Entities Common components and systems
    Unity.2D.Entities.Authoring Authoring for common 2D components
    Unity.2D.Entities.Hybrid Common editor components and systems
    Unity.2D.Entities.SpriteRenderer SpriteRenderer specific components and systems
    Unity.2D.Entities.SpriteRenderer.Authoring SpriteRenderer specific authoring
    Unity.2D.Entities.SpriteRenderer.Hybrid SpriteRenderer specific editor components and systems

    Changing the Sprite used by a Sprite Renderer

    To change the Sprite use by the Sprite Renderer, change the selected Entity in the Sprite property of the Sprite Renderer to another Entity with a Sprite component. The Sprite Renderer will start using the updated Sprite data for rendering. See below for a code example:

    var renderer = EntityManager.GetComponentData<SpriteRenderer>(spriteRendererEntity);
    renderer.Sprite = newSpriteEntity;
    EntityManager.SetComponentData(spriteRendererEntity, renderer);
    

    Ensuring Sprite Renderers are drawn as a batch

    Rendering with 2D Entities utilizes the same rendering pipeline as non-Dots Projects, and uses the same Draw call batching system as non-Dots Projects as well.

    Updating the sorting order of a Sprite Renderer at runtime

    All Entities with a Sprite Renderer component come with a Renderer2D component. If the sorting values in the Renderer2D component are updated, the Sprite Renderer will be sorted according to the changes. Similar to the default 2D Sorting of Sprite Renderers, Unity.U2D.Entities.SpriteRenderers are sorted according to the following order:

    1. Sort Layer. Higher value means closer to the camera.
    2. Sort Order. Higher value means closer to the camera.
    3. Distance between the position of the Renderer and the Camera along the Camera’s view direction. For the default 2D setting, this is along the (0, 0, 1) axis.

    See below for a code example:

    public class Example : SystemBase
    {
       protected override void OnUpdate()
       {
           // Loop over all Entities with SpriteRenderer and Renderer2D components
           Entities
               .WithAll<SpriteRenderer>()
               .ForEach((ref Renderer2D renderer) =>
               {
                   // Set SortLayer to 1
                   renderer.Layer = 1;
                   // Set SortOrder to 2
                   renderer.Order = 2;
               }).Schedule();
       }
    }
    
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023