[Bug] IDriveSource not assigned when player is already in car OnPlayerEnteredRoom (UCC2.2.5 / PUN-Add-on)

ChristianWiele

Active member
Hi,

when a player enters the room and another player is already in the car the Drive ability is immediately started to synchronize the state. Therefore the StartAbilityRPC is called on the remote client, bypassing the CanStartAbility method of the Drive ability. As a consequence the IDriveSource is not assigned as it is assigned in the ValidateObject method. But the remote client requires the IDriveSource to retrieve the colliders that have to be ignored. So the AbilityStarted method raises an exception.UCC2.2.5-Drive-PUN-Teleport-2.png
 
You should be able to move the following up to top of Drive.AbilityStarted:

Code:
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
            // The IDriveSource is responsible for notifying the remote players for the changes.
            if (m_NetworkInfo != null && !m_NetworkInfo.IsLocalPlayer()) {
                return;
            }
#endif

With remote players the CharacterLocomotion component doesn't actually update so it shouldn't be doing any collision detection. This is a similar reasoning for the other CharacterLocomotion calls (such as setting the platform).
 
Thanks, I will give it a try. I constantly struggled because collision detection was enabled on the remote client, and the car going wild. I will apply all the changes and let you know.
 
Unfortunately, this doesn't work. As expected, the Physics.IgnoreCollision is not synchronized.

Code:
 m_VehicleColliders = drivable.GetColliders();
            
            for (int i = 0; i < m_VehicleColliders.Length; ++i) {
                for (int j = 0; j < m_CharacterLocomotion.ColliderCount; ++j) {
                    Physics.IgnoreCollision(m_VehicleColliders[i], m_CharacterLocomotion.Colliders[j], true);
                }
            }

As a consequence the vehicle on the remote client goes wild.
 
I have now implemented my own solution. I moved the Physics.IgnoreCollision into the IDriveSource, and I send the character's viewID to the remote client with any sync call. The remote IDriveSource is then able to set the IgnoreCollisions correctly.
 
That does seem like a good solution. I was thinking of sending a new RPC within the Drive ability when a new client joins but in this case you wouldn't have to send a new one as you'd already be sending one within the IDriveSource. I'll switch the ability to do the same as you.
 
(y) Yes, this way the responsibility is clear, and you don't depend on the remote drive ability. Works very reliably so far.
 
Top