Ucc Performance Optimisation

Shanmukh

Member
I added 250 Agents to an empty scene. changed fixed update to update. they take 50ms.
Performence 1.JPG
its mainly on physics calculations.
UpdatePositionAndRotation(true); Running on OnAnimatorMove() in CharacterLocomation script.

1. i removed UpdatePositionAndRotation(true) method from OnAnimatorMove().
2. and also removed UpdatePositionAndRotation() from UpdatePositionAndRotation(bool fromAnimatorMove) method.
3. I added few lines in CharacterLocomation script.

Code:
         public void NowRunPhysicsCalculation()
        {
            UpdatePositionAndRotation(true);
        }
        bool collisionLayerEnabled;

        public void MyEnableCollider()
        {
            collisionLayerEnabled = m_CollisionLayerEnabled;

            EnableColliderCollisionLayer(false);
        }
        public void MyUpdatePlatformMovement()
        {
            UpdatePlatformMovement();
        }
        public void MyUpdateRotation()
        {
            UpdateRotation();
        }
        public void MyApplyRotation()
        {
            ApplyRotation();
        }
        public void MyUpdatePosition()
        {
            UpdatePosition();
        }
        public void MyApplyPosition()
        {
            ApplyPosition();
        }
        public void MyDisableCollider()
        {
            EnableColliderCollisionLayer(collisionLayerEnabled);
        }

4. I created a new script and write this.

Code:
using Opsive.UltimateCharacterController.Character;
using UnityEngine;
public class UccPhyscisBatching : MonoBehaviour

{
    public CharacterLocomotion[] CharacterLocomotionScript;
    int TotalCharacterCount;

    // Start is called before the first frame update
    void Start()

    {
        TotalCharacterCount = CharacterLocomotionScript.Length;
    }
    private void LateUpdate()

    {
        for (int i = 0; i < TotalCharacterCount; i++)
        {
            CharacterLocomotionScript.NowRunPhysicsCalculation();
        }

        for (int i = 0; i < TotalCharacterCount; i++)
        {
            CharacterLocomotionScript.MyEnableCollider();
        }
        for (int i = 0; i < TotalCharacterCount; i++)
        {
            CharacterLocomotionScript.MyUpdatePlatformMovement();
        }
        for (int i = 0; i < TotalCharacterCount; i++)
        {
            CharacterLocomotionScript.MyUpdateRotation();
        }
        for (int i = 0; i < TotalCharacterCount; i++)
        {
            CharacterLocomotionScript.MyUpdatePosition();
        }
        for (int i = 0; i < TotalCharacterCount; i++)
        {
            CharacterLocomotionScript.MyApplyPosition();
        }
        for (int i = 0; i < TotalCharacterCount; i++)
        {
            CharacterLocomotionScript.MyApplyRotation();
        }
        for (int i = 0; i < TotalCharacterCount; i++)
        {
            CharacterLocomotionScript.MyDisableCollider();
        }
    }

}

5. I attached this to an Empty gameobject and add all agents to the array and tested this is happened.
Performence 2.JPG
now it's running in 35ms. all physics calculations are batched.

if batch all raycasts ,rigidbody and collider calculations then performance will increase 50 to 60 percent.
see the link below
 
Last edited:
Hi Justin, Why don't you try to make all physics calculations independent of animations.
It gives a huge performance boost.
all Calculations Running under OnAnimatorMove() method.
 
Last edited:
I will need to look into that some more. I seem to remember that there were some problems related to root motion and the precise timing of the animations.
 
Top