Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Official 2D Entities 0.29 is now available

Discussion in 'Project Tiny' started by rustum, Aug 24, 2020.

  1. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    2D Entities 0.29 is out! This release is designed to work with Tiny 0.29 and requires Unity 2020.1.0f1 or newer

    Important Note: This release is targeted for Tiny 0.29 only. This means that it will not work with other versions of Tiny at this time. See this post for more information on what’s new in Tiny 0.29.

    What's in 2D Entities

    This is a foundational set of 2D features. As such it is focused on supporting basic rendering of sprites and collision detection in 2D.

    Rendering
    • Sprite
    • Sprite Renderer
    • Sprite Atlas
    • Runtime 2D rendering pipeline
    • Editor 2D rendering pipeline
    Physical Collision Detection
    • Primitive colliders
    • Compound collider
    • Rigidbody2D
    • Physics broadphase
    • Broadphase querying API

    Playable Demos
    Tiny Gems.png
    Play Tiny Gems


    Tiny Spaceship.png
    Play Tiny Spaceship


    Getting Started
    Here's a preconfigured project to get you started quickly:
    2D Entities Starter

    Samples:
    The source projects for the playable demos above are also available for you to explore. Find them here:
    Project Tiny Samples
    For this release the 2D Entities starter project and the sample projects have been upgraded to Unity 2020.1 and use 2D Entities 0.29.

    Documentation:
    For more detailed instructions on how to use 2D entities see the package docs here:
    2D Entities Package Docs
    In this version we have added the following information:
    • A 2D specific Getting Started section
    • What gets converted and how
    • An FAQ
    Please share your experience with the tools by replying to this post or creating a new one. How does this feature help you achieve your desired outcomes? What works as expected? And what doesn’t? We’re excited to hear back from you!

    We will be curating answers to frequently asked questions in the discussion.
     
  2. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    Known Issues
    • In the editor, the audio will not be played when triggered
    • You have to keep the Main Camera SubScene open in Edit mode at all times to see anything being rendered in the GameView window
    • There is a max string length to the build path
    • Sharing assets between SubScenes is currently not supported
    • Adding spaces in the Build Settings filename will cause the build pipeline to fail building
    • In the editor during Play Mode, the Scene View will not visualise the contents of a SubScene correctly, if the SubScene is in Edit Mode.
    • You must decorate your converter with the ConverterVersion attribute. You should increment the version number every time you change the converter.
    • Batching results will differ between editor and Project Tiny builds because they don't share the same render pipeline.
    • When minimizing and resuming an android application, the application will reboot.
     
    NotaNaN likes this.
  3. Luxxuor

    Luxxuor

    Joined:
    Jul 18, 2019
    Posts:
    89
    Great release so far!
    Is there anything specific required to enable collisions between converted Rigidbody2D components and static colliders? I was trying to setup a simple test using the 2D-Entities-Starter but my Rigidbody would never be halted/blocked from falling by a simple BoxCollider2D converted component.
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Hello @unity_Nb9eavDsBsU7WQ,
    Thank you for your feedback!

    Regarding collision response, this is a feature we are currently developing and will release in a future version of 2D Entities.
     
  5. djsell

    djsell

    Joined:
    Aug 29, 2013
    Posts:
    77
    Is there any support for rendering 2d and 3d together? I attempted to just drop a cube and light into the 2d entities starter project, but the cube did not seem to render in build.
     
    TwoBitMachines likes this.
  6. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    131
    Is it possible to use dynamic text for 2D 0.29 project?
     
  7. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916


    2D and 3D can be rendered together, however 2D will always be rendered on top of 3D content (this includes 3D Text).

    To render 3D, you need to use a project with the Universal Rendering Pipeline (URP). The easiest way to set everything up is to start by using Tiny3D and then add the 2D Entities package into the Tiny3D project.

    In the Tiny3D root assembly, be sure to add the following assemblies, to pull in the 2D rendering pipeline into the Tiny executable

     
    djsell and Maras like this.
  8. djsell

    djsell

    Joined:
    Aug 29, 2013
    Posts:
    77
    Works swell, thanks!
     
  9. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,163
    Is 2D entity responsible for UI and text and font for tiny?
     
  10. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @Thaina the 2D Entities package contains the following features:

    Rendering
    • Sprite
    • Sprite Renderer
    • Sprite Atlas
    • Runtime 2D rendering pipeline
    • Editor 2D rendering pipeline
    Physical Collision Detection
    • Primitive colliders
    • Compound collider
    • Rigidbody2D
    • Physics broadphase
    • Broadphase querying API
    The Tiny packages contains 3D text rendering, however, there is no UI solution for Project Tiny yet.
    For an overview of what features Project Tiny contains, see the Feature status summary.
     
    GilbertoBitt, NotaNaN and Thaina like this.
  11. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    So is there no LTS support with this package?
     
    Walter_Hulsebos likes this.
  12. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    I just got the 2D packages to start building, but when one object with a (non-trigger) collider contacts another (non-trigger) collider, it doesn't land on or get stopped by it, it just floats on through. Is this behaviour supposed to happen without custom logic, is this a bug, or is the predicted behaviour simply not implemented (yet)?
     
  13. djsell

    djsell

    Joined:
    Aug 29, 2013
    Posts:
    77
    There's no actual collision response yet. It's primarily for query purposes at the moment. Read above.

     
    dannyalgorithmic likes this.
  14. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @JamesArndt, no, there is no LTS support for this package. 2D Entities is still in an experimental phase where many of our foundational systems are being worked on. Once the development of the package stabilises, we will start supporting the package for long term usage. This is one of the reason why we do not advice to use the current version of 2D Entities in projects that are either live, or are aiming to go live in the near future.
     
    Walter_Hulsebos and JamesArndt like this.
  15. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Okay, awesome. Thank you for the response.
     
    Ted_Wikman likes this.
  16. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    Thanks, man. Response appreciated!
     
  17. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    V_i_T likes this.
  18. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @dannyalgorithmic since the 2D Entities public (and internal) API might change before we release the first verified version of the package, we will not create learn tutorials yet. We do however have a few examples in our package docs. We will make sure we always have a few examples in the package docs to explain general concepts within the package, using the latest API.
    If you find areas where we either haven't explained the concept properly, or not at all, do let us know and we will make sure to add it into the package docs.
     
    dannyalgorithmic likes this.
  19. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    I tried implementing the collision code as such, but I either get constant debug logs or none, as if it's either always colliding or never colliding, despite gravity pulling it down slowly, which should only make it overlap for a moment.

    Screenshot (55).png
     
  20. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    Btw, thanks a ton for the link!
     
  21. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @dannyalgorithmic,
    So there are two things to highlight in your code:
    1. The
    OverlapColliderInput
    also requires the colliders transform, so that the check knows there the collider is located. I saw that this is not noted in our docs, so I will make sure we add it in there in the next update.
    2. You are using
    .Schedule
    , which means that you are trying to multithread this job. In Tiny 0.29, multithreading is not supported, so you will not get any performance benefits from using
    .Schedule
    vs.
    .Run
    . However, if you do want to "future proof" your collision code, or just try out the multithreading in the editor, I'll leave the code for multithreading as well (it is a little bit different than running it on the main thread).

    Main threaded collision check:
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.U2D.Entities.Physics;
    3. using Unity.Transforms;
    4.  
    5. public class CollisionSystem : SystemBase
    6. {
    7.     protected override void OnUpdate()
    8.     {
    9.         var physicsWorld = World.GetExistingSystem<PhysicsWorldSystem>().PhysicsWorld;
    10.         Entities
    11.             .ForEach((
    12.                 in Entity colliderEntity,
    13.                 in PhysicsColliderBlob blob,
    14.                 in Translation translation,
    15.                 in Rotation rotation) =>
    16.             {
    17.                 var colliderInput = new OverlapColliderInput()
    18.                 {
    19.                     Collider = blob.Collider,
    20.                     Filter = CollisionFilter.Default,
    21.                     Transform = new PhysicsTransform(translation.Value, rotation.Value)
    22.                 };
    23.                 if (physicsWorld.OverlapCollider(colliderInput, out var hit))
    24.                 {
    25.                     if(colliderEntity == hit.Entity)
    26.                         UnityEngine.Debug.Log("Hit itself");
    27.                     else
    28.                         UnityEngine.Debug.Log($"Hit entity={hit.Entity.Index}");
    29.                 }
    30.             }).Run();
    31.     }
    32. }
    Multi-threaded collision check:
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.U2D.Entities.Physics;
    3. using Unity.Transforms;
    4.  
    5. using Unity.Jobs;
    6.  
    7. public class CollisionSystem : SystemBase
    8. {
    9.     protected override void OnUpdate()
    10.     {
    11.         var physicsWorldSystem = World.GetExistingSystem<PhysicsWorldSystem>();
    12.        
    13.         // Create a callback that is performed after the physics system has finished its frame calculations
    14.         physicsWorldSystem.ScheduleCallback(PhysicsCallbacks.Phase.PostExport,
    15.             (ref PhysicsWorld world, JobHandle deps) =>
    16.             {
    17.                 // Capture the Physics world variable, since you cant bring any references into a job
    18.                 var capturedWorld = world;
    19.                 deps = Entities
    20.                     .WithReadOnly(capturedWorld)
    21.                     .ForEach((
    22.                     in Entity colliderEntity,
    23.                     in PhysicsColliderBlob blob,
    24.                     in Translation translation,
    25.                     in Rotation rotation) =>
    26.                 {
    27.                     var colliderInput = new OverlapColliderInput()
    28.                     {
    29.                         Collider = blob.Collider,
    30.                         Filter = CollisionFilter.Default,
    31.                         Transform = new PhysicsTransform(translation.Value, rotation.Value)
    32.                     };
    33.                     if (capturedWorld.OverlapCollider(colliderInput, out var hit))
    34.                     {
    35.                         if(colliderEntity == hit.Entity)
    36.                             UnityEngine.Debug.Log("Hit itself");
    37.                         else
    38.                             UnityEngine.Debug.Log($"Hit entity={hit.Entity.Index}");
    39.                     }
    40.        
    41.                 }).Schedule(deps);
    42.        
    43.                 return deps;
    44.             });
    45.     }
    46. }
    Let me know if these code chunks and explanation solves your issue!
     
  22. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    131
    @Ted_Wikman is there an ETA when multithreading will be supported on each of the target platforms?
     
  23. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    I am speechlessly appreciative of this detailed and expedient support. :)

    Also, I really wasn't expecting it to be able to hit itself. I mean, I had considered it, but it made no sense and didn't know how to check, so I discarded the notion. XD
     
    Ted_Wikman and NotaNaN like this.
  24. JC-Cimetiere

    JC-Cimetiere

    Unity Technologies

    Joined:
    May 8, 2014
    Posts:
    123
    Multithreading is available for all supported build targets.
    To enable Multithreading, click on the “+” sign at the bottom of the Build Configuration inspector and add the DotsRuntimeScriptingSettings component.

    Then you can check “Enable Multithreading”.
    Note that Multithreading is not supported on Safari. One way to workaround is to set multithreading on in the Common build configuration inherited by others, and then create a specific WASM build configuration for Safari. The web template loading the build will have to be changed to select the correct build (we are doing some work to enable/document web template customization).

    In the future, we plan to add an automatic fallback to Single threading for Safari and do more work on Burst to improve web performance and size.

    Note, due to the nature of how multithreading is supported in the DOTS Runtime Tiny configuration, enabling Multithreading will automatically enable Burst Compilation as well. It is not possible to have multithreading enabled without burst compilation enabled in DOTS Runtime unless building for the non-Tiny configuration, Net Standard 2.0 on desktop.

    Hope this helps!
    JC
     
    Thaina, NotaNaN and Maras like this.
  25. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    131
    @JC-Cimetiere so Ted was talking only about the physics system multithreading? I still get quite poor performance on Tiny Racing and thought it is just because the multithreading is not supported.
     
    JC-Cimetiere and NotaNaN like this.
  26. JC-Cimetiere

    JC-Cimetiere

    Unity Technologies

    Joined:
    May 8, 2014
    Posts:
    123
    Well sorry it's confusing. Builds with Multithreading compiles & runs but we haven't completed all optimization & stabilization work. You might not see yet real performance improvements, and feel free to share any issue you discover.
     
    Maras likes this.
  27. Luxxuor

    Luxxuor

    Joined:
    Jul 18, 2019
    Posts:
    89
    When using the 2D-Entities package and turning on multithreading I always get crashes on macOS 10.15. The crash is not always in the same method but most of the time it is in one of the worker threads and related to the 2D physics system.
    Example log:

    Thread 6 Crashed:: job-queue.worker-bee 3
    0 libsystem_kernel.dylib 0x00007fff6a94733a __pthread_kill + 10
    1 libsystem_pthread.dylib 0x00007fff6aa03e60 pthread_kill + 430
    2 libsystem_c.dylib 0x00007fff6a8ce808 abort + 120
    3 libc++abi.dylib 0x00007fff67b2d458 abort_message + 231
    4 libc++abi.dylib 0x00007fff67b1e7e9 demangling_terminate_handler() + 48
    5 libc++abi.dylib 0x00007fff67b2c887 std::__terminate(void (*)()) + 8
    6 libc++abi.dylib 0x00007fff67b2c838 std::terminate() + 56
    7 lib_burst_generated.dylib 0x0000000112aff7c3 Unity.Collections.NativeSlice`1<Unity.U2D.Entities.Physics.PhysicsBody>.get_Item(Unity.Collections.NativeSlice`1<Unity.U2D.Entities.Physics.PhysicsBody>* this, int index)_07B9B62CA933ADDE + 259 (NativeSlice.cs:198)
    8 ??? 0x0000000200000028 0 + 8589934632
    9 ??? 0xc040000000000000 0 + 13853072453791645696
     
  28. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    @Luxxuor could you share with us how you are using the physics feature set?
     
  29. Luxxuor

    Luxxuor

    Joined:
    Jul 18, 2019
    Posts:
    89
    Mostly just manipulating the PhysicsVelocity of a converted Rigidbody2D (simple platformer mechanics), although I am using ScheduleParallel which might be the problem?

    Code (CSharp):
    1. using Unity.Collections;
    2. using Unity.Entities;
    3. using Unity.U2D.Entities.Physics;
    4. using static Unity.Mathematics.math;
    5.  
    6. namespace Runtime
    7. {
    8.     // ReSharper disable once UnusedType.Global
    9.     [UpdateAfter(typeof(KeyboardInputSystem))]
    10.     [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    11.     public sealed class MovementSystem : SystemBase
    12.     {
    13.         private EndFixedStepSimulationEntityCommandBufferSystem ecb;
    14.  
    15.         protected override void OnCreate()
    16.         {
    17.             base.OnCreate();
    18.  
    19.             ecb = World.GetOrCreateSystem<EndFixedStepSimulationEntityCommandBufferSystem>();
    20.  
    21.             RequireSingletonForUpdate<GameplayInputs>();
    22.         }
    23.  
    24.         protected override void OnUpdate()
    25.         {
    26.             var inputs = GetSingleton<GameplayInputs>();
    27.             var cmd = ecb.CreateCommandBuffer().AsParallelWriter();
    28.  
    29.             Entities
    30.                 .WithNone<Airborne>()
    31.                 .ForEach((Entity e, int entityInQueryIndex, ref PhysicsVelocity velocity, ref PhysicsGravity gravity, ref Direction direction,
    32.                     in Movement movement) =>
    33.                 {
    34.                     if (inputs.MoveRight.Down)
    35.                     {
    36.                         direction.Value = LookDirection.Right;
    37.                         velocity.Linear.x = min(velocity.Linear.x + movement.HorizontalAcceleration, movement.MaxSpeed);
    38.                     }
    39.                     else if (inputs.MoveLeft.Down)
    40.                     {
    41.                         direction.Value = LookDirection.Left;
    42.                         velocity.Linear.x = max(velocity.Linear.x - movement.HorizontalAcceleration, -movement.MaxSpeed);
    43.                     }
    44.                     else
    45.                     {
    46.                         // do not update the direction the character is looking to, but do update the velocity
    47.                         velocity.Linear.x = 0f;
    48.                     }
    49.  
    50.                     if (inputs.Jump.PressedThisFrame)
    51.                     {
    52.                         velocity.Linear.y = movement.JumpPower;
    53.                         gravity.Scale = movement.RisingGravityScale;
    54.                         cmd.AddComponent(entityInQueryIndex, e, new Airborne(direction.Value));
    55.                     }
    56.                 }).ScheduleParallel();
    57.  
    58.             Entities
    59.                 .ForEach((ref PhysicsVelocity velocity, in Airborne airborne, in Movement movement) =>
    60.                 {
    61.                     if (inputs.MoveRight.Down)
    62.                     {
    63.                         var maxSpeed = GetAirMaxSpeed(LookDirection.Right, airborne, movement);
    64.                         var accel = movement.HorizontalAcceleration;
    65.                         velocity.Linear.x = min(velocity.Linear.x + accel, maxSpeed);
    66.                     }
    67.                     else if (inputs.MoveLeft.Down)
    68.                     {
    69.                         var maxSpeed = GetAirMaxSpeed(LookDirection.Left, airborne, movement);
    70.                         var accel = movement.HorizontalAcceleration;
    71.                         velocity.Linear.x = max(velocity.Linear.x - accel, -maxSpeed);
    72.                     }
    73.                     else
    74.                     {
    75.                         velocity.Linear.x = 0f;
    76.                     }
    77.                 }).ScheduleParallel();
    78.  
    79.             ecb.AddJobHandleForProducer(Dependency);
    80.         }
    81.  
    82.         [BurstCompatible]
    83.         private static float GetAirMaxSpeed(LookDirection inputDirection, in Airborne airborne, in Movement movement) =>
    84.             movement.CommitJumpDirection
    85.                 ? airborne.Direction == inputDirection
    86.                     ? movement.AirForwardMaxSpeed
    87.                     : movement.AirBackwardMaxSpeed
    88.                 : movement.MaxSpeed;
    89.     }
    90. }
    I can also provide a repro project if necessary.
     
  30. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    You are missing the usual boilerplate to deal with the physics systems:
    Code (CSharp):
    1.     [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    2.     // usually those are the right ones, not sure why
    3.     [UpdateAfter(typeof(StepPhysicsWorld))]
    4.     [UpdateBefore(typeof(EndFramePhysicsSystem))]
    5.     public class MySystem : SystemBase
    6.     {
    7.         private EndFramePhysicsSystem _endFramePhysicsSystem;
    8.         private StepPhysicsWorld _stepPhysicsWorld;
    9.  
    10.         protected override void OnCreate()
    11.         {
    12.             // cache them
    13.             _endFramePhysicsSystem = World.GetExistingSystem<EndFramePhysicsSystem>();
    14.             _stepPhysicsWorld = World.GetExistingSystem<StepPhysicsWorld>();
    15.         }
    16.  
    17.         protected override void OnUpdate()
    18.         {
    19.             // add the OutputDependency of the physics system you are updating after
    20.             Dependency = JobHandle.CombineDependencies(Dependency, _stepPhysicsWorld.GetOutputDependency());
    21.  
    22.             // do your stuff
    23.  
    24.             // add the updated Dependency as the InputDependency to the physics system you are updating before
    25.             _endFramePhysicsSystem.AddInputDependency(Dependency);
    26.         }
    27.     }
    28.