Crash in UMassAgentComponent::UnregisterWithAgentSubsystem when state is PuppetPendingReplication

We are experiencing crashes in UE 5.6 when simulated proxy pawns are removed before UMassAgentComponent::OnRep_NetID() has run. In this case, UMassAgentComponent::UnregisterWithAgentSubsystem() is called while the component is still in the PuppetPendingReplication state, which fails the MASSAGENT_CHECK assertion and crashes the client.This seems to match the issue reported in the public Unreal Engine forums: https://forums.unrealengine.com/t/ue-5-6-massagentcomponent-bug/2607675

unknown 0x00004000 / 0x7ffe3dbe9f0a: Fatal Error: unknown 0x00004000 / 0x7ffe3dbe9f0a
  ?, in UMassAgentComponent::UnregisterWithAgentSubsystem
  ?, in UMassAgentComponent::OnUnregister
  File "ActorComponent.cpp", line 1843, in UActorComponent::ExecuteUnregisterEvents
  File "ActorComponent.cpp", line 1553, in UActorComponent::UnregisterComponent
  File "Actor.cpp", line 5473, in AActor::UnregisterAllComponents
...
(45 additional frame(s) were not displayed)
 
Assertion failed: State == EAgentComponentState::None || State == EAgentComponentState::PuppetPaused || State == EAgentComponentState::PuppetReplicatedOrphan [File:D:\Horde\Work\ULIncMain\Sync\Engine\Plugins\Runtime\MassGameplay\Source\MassActors\Private\MassAgentComponent.cpp] [Line: 131] 
UMassAgentComponent::UnregisterWithAgentSubsystem is expecting to be in state[None|PuppetPaused|PuppetReplicatedOrphan] state but is in EAgentComponentState::PuppetPendingReplication

Steps to Reproduce
This is from the bug ticket here: UE 5.6 MassAgentComponent Bug

  1. Player1 login
  2. 2.Player2 login
  3. 3.Player2’s SimulatedProxy Character->MassAgentComponent->RegisterWithAgentSubsystem() on Player1 client
  4. 4.Player2’s SimulatedProxy Character Remove on Player1 client
  5. 5.Player2’s SimulatedProxy Character->MassAgentComponent->UnregisterWithAgentSubsystem() MASSAGENT_CHECK on Player1 client

I have been speaking with some of our devs who worked on this originally, but everyone’s memory of what was being done or needed to be done is quite fuzzy as we have not done much with this since 5.0 launched.

Our consensus is that this is an unhandled case which we did not encounter when first working on this code. I think it should be okay to add the PuppetPendingReplication state to the valid states for the MASSAGENT_CHECK when unregistering, but I would add an early out of the function before running the other logic. I am not sure if the other logic when unregistering may have issues with not all data for the entity being replicated yet. If you make any of these changes, we would love to know if you see other issues, fallout, or even if everything just works as expected.

-James

Perfect James, thanks a lot. We will try what you suggested and let you know what the outcome is.

1 Like