Search Unity

make 3D animation work with DOTS and ECS

Discussion in 'Animation' started by Michelle_Ca, Apr 19, 2020.

  1. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    I am converting my project to DOTS
    I've converted all the MonoBehaviour scripts to IComponentData and ComponentSystem
    I am using (Convert To Entity) to convert the Prefabs and instantiate them as Entities
    The problem is that the Prefabs contain a (Skinned Mesh Renderer) and (bones) and this does not work with DOTS according to the error that appears
    Is there a way to make this work?
    Perhaps a way to separate Render and Animation from the Entities and keep them MonoBehaviour ?
    please any help !
     
  2. Filtiarn_

    Filtiarn_

    Joined:
    Jan 24, 2013
    Posts:
    173
    Here is what I am doing.
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Physics;
    3. using Unity.Mathematics;
    4. using UnityEngine;
    5. using UnityEngine.PlayerLoop;
    6.  
    7. namespace DOTSActorCore
    8. {
    9.     [UpdateAfter(typeof(ActorActionMovementSystem))]
    10.     public class ActorAnimationLegacySystem : ComponentSystem
    11.     {
    12.         float deltaTime;
    13.         float x;
    14.         float z;
    15.  
    16.         protected override void OnUpdate()
    17.         {
    18.             deltaTime = Time.DeltaTime;
    19.  
    20.             Entities.WithAll(typeof(ActorGroundedTagComponent)).ForEach((Animator animator, ref PhysicsVelocity physicsVelocity, ref ActorActionMovementComponent action, ref ActorInputComponent actorInputComponent) =>
    21.             {
    22.                 var velocity = physicsVelocity.Linear;
    23.                 var movementMagnitude = ((Vector3)velocity).magnitude;
    24.  
    25.                 z = movementMagnitude / action.walkRunSpeed;
    26.                 if (actorInputComponent.doSpeedUp)
    27.                     z = movementMagnitude / action.sprintSpeed * 2;
    28.    
    29.  
    30.                 if (actorInputComponent.moveInput.x == 0 && actorInputComponent.moveInput.y == 0)
    31.                 {
    32.                     x = 0;
    33.                     z = 0;
    34.                 }
    35.  
    36.                 animator.SetFloat("movementX", x, 0.1f, deltaTime);
    37.                 animator.SetFloat("movementZ", z, 0.1f, deltaTime);
    38.                 animator.SetBool("isGrounded", true);
    39.                 animator.SetBool("isPivoting", action.isPivoting);
    40.                 animator.SetBool("isCrouching", actorInputComponent.doCrouch);
    41.                 animator.SetBool("isSwimming",false);
    42.  
    43.                 animator.SetFloat("leanX",action.leanX,0.2f,deltaTime);
    44.  
    45.                 if (action.didJustJump)
    46.                     animator.SetTrigger("doJump");
    47.             });
    48.  
    49.             Entities.WithNone(typeof(ActorGroundedTagComponent)).ForEach((Animator animator) =>
    50.             {
    51.                 animator.SetBool("isGrounded", false);
    52.             });
    53.         }
    54.     }
    55. }
    56.  
    57.  
     
    Michelle_Ca likes this.