• We are looking for a content creator to help market our assets and a future unannounced project. More details are on this page.

Call SyncTransform Once Instead of per Character on FixedUpdate?

airoll

Member
Hi, I was profiling my game today and I noticed that a lot of the CPU resources are tied up in KinematicObjectManager.FixedUpdate(), specifically on when Physics.SyncTransforms is called.

1652554890152.png

I was wondering, given the guidance here, would it be better to batch the Physics.SyncTransforms() once as opposed to calling it multiple times per character? The same applies to the call in KinematicObjectManager.BeginCharacterMoveInternal().

KinematicObjectManager.FixedUpdate()
C#:
 for (int i = 0; i < m_CharacterCount; ++i) {
                if (m_Characters[i].CharacterLocomotion.UpdateLocation == UpdateLocation.Update) {
                    continue;
                }
                if (!m_AutoSyncTransforms) {
                    Physics.SyncTransforms();
                }

                m_Characters[i].Move(false);
                
                if (m_Characters[i].CharacterIK != null && m_Characters[i].CharacterIK.enabled)
                {
                    m_Characters[i].CharacterIK.Move(true);
                }

                // If FixedUpdate is called multiple times before Update then the framerate is low.
                // Update the position immediately to prevent jittering.
                if (m_FixedUpdate)
                {
                    m_Characters[i].AssignFixedLocation(true);
                }
            }

C#:
        /// <summary>
        /// Internal method which indicates that the character has started moving.
        /// </summary>
        /// <param name="characterIndex">The index of the character within the characters array.</param>
        private void BeginCharacterMovementInternal(int characterIndex)
        {
            if (characterIndex < 0) {
                return;
            }

            if (!m_AutoSyncTransforms) {
                Physics.SyncTransforms();
            }

            var updateLocation = m_Characters[characterIndex].CharacterLocomotion.UpdateLocation;
            if (updateLocation == UpdateLocation.FixedUpdate) {
                m_Characters[characterIndex].RestoreFixedLocation();
            }

            // If the character has a camera attached the camera should first be rotated.
            int cameraIndex;
            if (m_Characters[characterIndex].AttachedCamera != null && (cameraIndex = m_Characters[characterIndex].AttachedCamera.KinematicObjectIndex) >= 0) {
                m_Cameras[cameraIndex].Rotate();
            }
        }

Thanks!
 

Justin

Administrator
Staff member
I needed to call it multiple times to allow other characters to correctly determine the location during their update cycle. In version 3 I have a much improved locomotion system and the KinematicObjectManager no longer exists so it won't be long that this limitation is there.
 
Top