I just need make simple thing, players set name, and on begin play apply it. But need some check what is mine unit. Why in UE so hard check what is mine unit? Its have roles - but its alwayes diffrenets and give me nothing. I find only 1 solution. bool OwnedLocally =IsOwnedBy(UGameplayStatics::GetPlayerController(this, 0)); Its good way?
what actor do you need it on?
pawn has islocallycontrolled()
controller has islocalplayercontroller()
islocallycontrolled() is worked only for one player, others players always has false.
I not sure what you mean. I spawn 1 actor player for each player from game mode.
that only works on pawn i believe, what kind of actor are you testing?
Its character actor.
Oh, its worked, but i make logic in begin play, but LocallyControlled worked after OnPosses, sometimes its work after BeginPlay.
is the character possessed by the player controller? if not youll need another ref to the Player
I think the problem is that “on possess” and “on begin play” are asynchronous. Plus, “possessing” callbacks only happens on servers, not on clients. Instead, you’ll have to signal some property from the server and respond to it replicating on the client.
My characther spawn logic - in player controller check is Locally in begin play - call server void (Ufunction server) this function cast to GameMode, and call function in GameMode with ref to controller (ServerSpawnPlayer (APlayerController* NewPlayer)), in this void in game mode i set Posses with ref.
is the player ref replicated?
also even replicated it’ll be invalid on non owning clients
I not sure what you mean. Player Controller exist on server and on client. Its not anything replicated. IsLocallyControlled work fine, but its not work in BeginPlay, its works later.
I just use PossessedBy, for start init locally data, here checking start work fine.
only the owning player controller exists on the client, meaning client 1 cant get client 2s controller but the server can get everyones
BeginPlay is not the place to do this type of check as @jwatte points out as it can happen before or after you know if you are the owner of the Actor.
You can override OnRep_Owner instead and if GetNetConnection() doesn’t return nullptr this would indicate that the Actor is owned by the current client.
If you use a ListenServer then it obviously won’t have a NetConnection to itself and OnRep won’t be called either but you can use GetNetOwningPlayer to check if the ListenServer itself owns the Actor.
In pawn/character classes you can use event ReceivePlayerController
instead of BeginPlay, this should be a good place to check ownership. And since the playercontroller link is already done when the event is called, you can use isLocallyControlled directly.
Having to override both OnRep_Owner (network client) and OnPossessed (network server) is such a pain.
Using Event Receive Controller Changed is much better. (There’s no “ReceivePlayerController” event, but Controller Changed is probably what you were referencing.)
I totally agree.
My answer was directed at Actors in general that are not Pawns.
Thanks. I check it.