• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by captainspaceman · Jan 17, 2021 at 05:17 AM · dots

Performance gain with DOTS not very big

I followed this tutorial Getting Started with ECS in Unity 2019 and he was able to easily get 100,000 sprites on the screen, I can't get more than 30,000, which is more than with the classical system but not nearly the gain I was supposed to get.

So I was just wondering what were some of the common reasons it might be slower than it should? I have burst compiler enabled, and my profiler looks like this alt text

Everything is the same as the guy's tutorial so has DOTS just gotten slower in the year and a half since the video? Here is how to recreate my project, unzip this package DOTS test assets and import it into a 2D scene. You have to have the entities package installed, and the hybrid renderer. Then, make an empty object and put the testing script on it. Select the quad for the mesh and the weird animal sprite material for the material. Then just click play. The amount of objects you spawn is in the testing script. Again, I can only get 30,000 above 30fps, everyone else can get like 100,000 sometimes 200,000. I tried it on my laptop which has a newer i7 in it to see if it would make a difference and it ran worse I guess because it doesn't have a gpu. Thanks for any help!

dots-profiler.png (15.2 kB)
dots-test-assets.zip (11.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by andrew-lukasik · Jan 17, 2021 at 11:43 PM

(1). Enable GPU Instancing in shader to cut on those render batches.

100 or 3k render batches is fine. 30000 render batches will convert most computers into a stove.


(2). Optimize your code

 using UnityEngine;
 using Unity.Entities;
 using Unity.Transforms;
 using Unity.Rendering;
 using Unity.Mathematics;
 
 // FYI: starting class names with lowe-case letters is criminal...
 public class testing : MonoBehaviour
 {
     [SerializeField] Mesh _mesh;
     [SerializeField] Material _material;
     [SerializeField] int _amount = 30000;
     
     private void Start ()
     {
         EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
 
         EntityArchetype entityArchetype = entityManager.CreateArchetype(
             // prefabs aren't visible nor active
             // var instance = entityManager.Instantiate( prefab ); - removes this tag for instances
             typeof(Prefab) ,
             
             // typeof(Translation) // local position needs to be converted to LocalToWorld every sim frame so lets get rid of it
             typeof(LocalToWorld) ,// transform
             typeof(RenderMesh) ,
             ComponentType.ChunkComponent<RenderBounds>() ,
             typeof(WorldRenderBounds) ,
             ComponentType.ChunkComponent<ChunkWorldRenderBounds>() ,
 
             typeof(MoveSpeedComponent)
         );
 
         var prefab = entityManager.CreateEntity( entityArchetype );
         {
             entityManager.SetSharedComponentData( prefab , new RenderMesh{
                 mesh = _mesh,
                 material = _material
             } );
         }
         RenderBounds renderBounds = new RenderBounds{ Value = _mesh.bounds.ToAABB() };
 
         var random = new Unity.Mathematics.Random( seed: (uint) System.DateTime.Now.GetHashCode() );
         for( int i=0 ; i<_amount ; i++ )
         {
             Entity entity = entityManager.Instantiate( prefab );
 
             var chunk = entityManager.GetChunk( entity );
             entityManager.SetChunkComponentData<RenderBounds>( chunk , renderBounds );
 
             float3 pos = new float3{ x=random.NextFloat(-5f,5f) , y=random.NextFloat(-5f,5f) , z=0f };
             quaternion rot = quaternion.identity;
             float3 scale = new float3{ x=1 , y=1 , z=1 };
             entityManager.SetComponentData( entity , new LocalToWorld{
                 Value = float4x4.TRS( pos , rot , scale )
             } );
 
             entityManager.SetComponentData( entity , new MoveSpeedComponent{
                 moveSpeed = random.NextFloat(1f,2f) ,
                 up = true
             } );
         }
     }
 }

Your MoverSystem was not multi-threaded nor burst-compiled, a fix:

 using Unity.Mathematics;
 using Unity.Entities;
 using Unity.Transforms;

 public class MoverSystem : SystemBase
 {
     protected override void OnUpdate ()
     {
         float dt = Time.DeltaTime;
 
         Entities
             .WithName("translation_job")
             .ForEach( ( ref LocalToWorld transform , ref MoveSpeedComponent moveSpeedC ) =>
             {
                 float3 position = transform.Position;
 
                 position.y += moveSpeedC.moveSpeed * dt;
                 if( position.y>5 && moveSpeedC.up )
                 {
                     moveSpeedC.moveSpeed *= -1f;
                     moveSpeedC.up = false;
                 }
                 else if( position.y<-5 && !moveSpeedC.up )
                 {
                     moveSpeedC.moveSpeed *= -1f;
                     moveSpeedC.up = true;
                 }
                 moveSpeedC.level += 1f * dt;
                 
                 transform.Value = float4x4.Translate( position );//float4x4.TRS( pos , rot , scale )
             })
             .WithBurst().ScheduleParallel();
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

157 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Label dots in between numbers (currency formatting) 2 Answers

How to determine which side of an object the player collided with? 2 Answers

Acessing static variable from Entities.ForEach 1 Answer

DOTS Grid-based generation question. 1 Answer

Where is com.unity.animation? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies 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.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges