Replicate an actor reference/pointer

Hi,

I am implementing a selection system in a multiplayer game. The player can click on an actor (client-side), and I want to call a meyhod of this actor on the server.

Problem is : how can I transmit the actor’s reference over the wire ? Obviously a pointer can’t work, what should I do ?

Thanks !

You can actually refer to these as pointers over the wire :slight_smile:

If this is a static actor (loaded with the level), it should just work. If the actor is dynamic (spawned during play), it will need to be a replicated actor, and relevant.

Assuming the actor is static or replicated, just refer to it as you normally would in RPC calls. If this is a property on an actor that refers to another actor, just mark that property as replicated.

Hope this helps!

To clarify, if the actor you are referencing is dynamic but not relevant, you can still refer to it over the wire, it will just be sent as a NULL pointer to non relevant clients. This is normal behavior, and the client should be resilient to this.

In the case where a dynamic actor is not marked as replicated, but is being referred to, it will also be sent as NULL. This is a weird case though, and should be avoided, since it doesn’t make much sense to refer to this type of actor over the wire (the engine won’t crash, but this could be a misleading case for game code).

Yes, that should work.

Thanks !

What about Pawns, Controllers, AIControllers, Weapons ? Those are primarily the ones I want to play with. Can I simply pass an AIController* parameter to a “server” method from a client, and expect the correct result ?

Thank you so much. This is awesome !