Download

Can I get a callback on the server when actors' transforms replicate?

I want to send transform position to a non-Unreal client (Maya connected via a custom socket) every time an actor moves in the level (i.e. it’s movement is replicated to connected clients). Is there any easy way to do this?

I know OnRep will callback when a specific variable replicates, but I want a callback whenever any arbitrary actor’s transform change is replicated.

Otherwise I have to set up my own dirty bit registry for actors’ movement, which seems like a wasteful redundancy.

OnRep_ReplicatedMovement() and OnRep_AttachmentReplication(). To make life easier you can probably just use PostNetReceiveLocationAndRotation().

This is an actor function you can override on a per-actor-class basis. There is no generic/global callback for every actor. Perhaps you can use USceneComponent::TransformUpdated, but it likely won’t be fast and will be called for every component.

That’s what I feared-thanks at least for pointing out ReplicatedMovement. Given that I’m using USD to generically (and dynamically) load objects into a level, I’m not sure there’s a simple way to access those callbacks.

I was secretly hoping for a callback that gave me the name of an actor that had been replicated in some way. Then I could just query their transform.

But thanks for the reply!

Looks like my best bet is to add a hook in ServerReplicateActors() in NetworkDriver.cpp

Be aware that ServerReplicateActors() only runs on the Server (as the name suggests) - not sure if that’s what you’re after.

If you’re open to modifying the engine for this and you only need this for the Server, you can add a hook to AActor::PreReplication(). That will give you a specific actor reference more easily, and you can even check if the FRepMovement struct has changed there too (the engine does this through GatherMovement()).

Cool, thanks. Yes, it’ll run on the server. One last question: when PreReplication() is called has the actor already been moved to its new position? I’m assume that’s the case.