RealDocs

AActor::OnSerializeNewActor

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

Description

Called on the server immediately before a new actor is serialized and sent to a connecting client. Override to write any custom spawn-time data into the bunch that OnActorChannelOpen will read on the client.

Caveats & Gotchas

  • Data written here must be read back in exactly the same order and types in OnActorChannelOpen on the client. Any mismatch will corrupt the bunch and may close the connection.
  • This is a one-time send at spawn — the data is not resent on subsequent replication ticks. Use replicated properties for state that changes after spawn.
  • Writing too much data here bloat the open-channel bunch. Keep it minimal — only data that must arrive before the first property update.

Signature

virtual void OnSerializeNewActor(class FOutBunch& OutBunch) {};

Parameters

Name Type Description Default
OutBunch class FOutBunch& The outgoing bunch to write custom spawn-time data into before the actor is serialized to the client.

Return Type

void

Example

Writing custom spawn flags into the bunch C++
void AMyActor::OnSerializeNewActor(FOutBunch& OutBunch)
{
	Super::OnSerializeNewActor(OutBunch);
	// Pack flags into a single byte to minimise bandwidth
	uint8 SpawnFlags = bSpecialSpawn ? 0x01 : 0x00;
	OutBunch << SpawnFlags;
}

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.