RealDocs

AActor::OnNetCleanup

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: virtual

Description

Called when the net connection associated with this actor is being closed or destroyed. Override to release any resources or state tied specifically to that connection.

Caveats & Gotchas

  • This is called on the server when the owning client disconnects. It is NOT called on clients — use EndPlay or other lifecycle hooks for client-side cleanup.
  • The actor itself is not necessarily being destroyed when this fires — for example, an AI actor that was temporarily owned by a player retains its own lifetime after the player leaves.
  • Avoid calling ReplicatedProperties setters here; the connection is already being torn down and any changes will not be sent.

Signature

virtual void OnNetCleanup(class UNetConnection* Connection) {};

Parameters

Name Type Description Default
Connection class UNetConnection* The net connection that is being torn down.

Return Type

void

Example

Releasing connection-specific state on disconnect C++
void AMyPlayerController::OnNetCleanup(UNetConnection* Connection)
{
	// Release any per-connection streaming requests before the connection closes
	if (StreamingHandle.IsValid())
	{
		StreamingHandle->CancelHandle();
		StreamingHandle.Reset();
	}
	Super::OnNetCleanup(Connection);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.