How to compare player controllers after replication

I’m doing a fog-of-war kind of thing, in a networked game.

On the server, when a detector actor for a particular player gets close enough to some other actor, that other actor updates a set of “seen by players” PlayerController Set, and broadcasts a (reliable) event saying “add this playercontroller to the set of players that have seen the actor.”

In the actor, I then want to make it invisible, unless the local player controller is in the set of player controllers who have seen it.

Actors are spawned by some particular player, who is the Owner for the actor, and that player initially goes in the set.

I have two problems getting this to work:

  1. Inside the possibly-invisible Actor, I need to get “the local player controller” to check whether it’s in the set. I think that just “get player controller at index 0” will always do this, because I never support splitscreen – is this correct?

  2. I seem to recall that player controllers aren’t really replicated – so, what will happen to the player controller value as it gets broadcast to other players? Does it turn into a dummy empty controller of some other class? Does it get ignored? Turned to NULL? E g, if I’m client X, and my instance of the invisible-actor A gets the message “seen by player Y,” what will the value of Y be in the event handler?

Yes, if invisibility was important, I would arrange for the actor to not even get replicated to players that haven’t “seen” it, so that there could be no maphacks. This is not a use case where this is important. (That being said, if doing so is actually the easiest way to get this done, sure, point me in that direction instead!)

Hi, as for

  1. I always use “get player controller at index 0” to get the local player controller and didn’t run into any issues as of yet, so I guess thats correct.

  2. AFAIK the only player controller that exists on a client is its local player controller. In blueprints if I try to send a reference to an object that does not exist on where I send it to, it will be null. Never tried it in C++ though, but I guess it will be either null or garbage.

It seems to me that you not need any replication for this at all, so maybe consider doing it locally on the client. But if some client sees this actor should be known by other clients, then you will need replication. I never used much replication in C++, only the basics, so no idea whether there might be a much better way to achieve this with some replication conditions.

1 Like

That’s true, if I believe the client simulation will be accurate enough compared to server, then I could do it client side only in this case!

Thanks for the answer. I’m looking at using PlayerState now instead. If that doesn’t work as a key, I’ll end up with the player ID out of the player state.