CQTest - ClientConnections not being cached properly

Hi,

In 5.6, some of our network tests have started to fail, we are doing some operations with the ClientConnections cached in FBasePIENetworkComponentState, but all of the UNetConnections in that Array are null. It looks like the Component isn’t caching them properly anymore.

I noticed a change in CL 35177122 where a new function ( ConnectionClientsToServer() ) in PIENetworkComponent.cpp caches the existing connections from the NetDrive, but the for loop is starting from number of elements already in the ClientConnections array, which is initialised in a previous step with the ClientCount, essentially starting the loop at the end of the array.

I was also able to reproduce this problem in a blank project:

`#if ENABLE_PIE_NETWORK_TEST

NETWORK_TEST_CLASS( CustomNetworkTests, GenerateTestDirectory )
{
FPIENetworkComponent< FBasePIENetworkComponentState > Network { TestRunner, TestCommandBuilder, bInitializing };

BEFORE_EACH()
{
FNetworkComponentBuilder< FBasePIENetworkComponentState >()
.WithClients( 1 )
.WithGameInstanceClass( UGameInstance::StaticClass() )
.WithGameMode( AGameModeBase::StaticClass() )
.Build( Network );

TSharedRef< FNetworkGUID > SharedGuidForCharacter = MakeShared< FNetworkGUID >();

Network.ThenServer( TEXT( “Example Test” ), [&]( FBasePIENetworkComponentState & ServerState )
{
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
ServerState.TestCharacter = ServerState.World->SpawnActor< APlatformingCharacter >( SpawnParameters );

UNetConnection* ClientConnection = ServerState.ClientConnections[ 0 ];
// ClientConnection is Null.
}
}
}

#endif // ENABLE_PIE_NETWORK_TEST`

Is there an additional set up that I am missing or is this a bug?

Thanks in advance,

Felipe

Thanks for reporting this issue.

To fix this you can modify the file PIENetworkComponent.cpp

Looks for the method FBasePIENetworkComponent::ConnectClientsToServer()

And change first 2 lines to this:

void FBasePIENetworkComponent::ConnectClientsToServer() { auto& ServerConnections = ServerState->World->GetNetDriver()->ClientConnections; for(int32 ClientIndex = 0; ClientIndex < ServerState->ClientCount; ClientIndex++)The fix was suggested through this PR: https://github.com/EpicGames/UnrealEngine/pull/13605

And will be part of a future release.

That’s great! Thanks for clarifying it, Jerome.