Server RPC on Player Controller not doing anything for the pawn

Everything I’ve read says this should work. Actors are all replicated properly, AFAIK. This runs ok when the listen-server starts up, but the casts all seem to fail and the clients don’t update.

Which of these Casts actually fail?
It’s really important to know which work and which fail.

And if one of them fails (with Accessed None error!), grab what ever you are using as “Object” for that cast
and print the DisplayName. Check if it’s actually what you expect it to be.

The replication part looks ok for me.

But what cast does fail? That’s important to know.
And in what blueprint are these nodes? Especially the GetOwner->CastTOBBVRPlayerController looks suspicious for me.
You set the VRGameInst under Edit->ProjectSettings and BBVRPlayerController in the gamemode, did you?

The background on this, @Pepeeee , is the following.

Obviously network, he wants to get the PlayerName from the Client after he joined.
It’s not wired with Steam or something, so it needs to be stored locally on the client and retrieved after joining.

And the logic itself looks fine to me.

Now he wants to pass that PlayerName to the PlayerCharacter that is connected to the PlayerState.

Normally, the PlayerController owns the PlayerState, so “GetOwner” should be the PlayerState.

I’m like 98% sure, but could also be wrong :stuck_out_tongue:

What he could do is, move the logic into the PlayerCharacter itself. Then it would be called every time
the PlayerCharacter is destroyed and recreated, which is “ok” but not optimal.

The current approach is also not optimal though.

He’s using a TextRenderer on the PlayerCharacter, that’s what the RepNotify function is setting at the end,
after the variable get replicated correctly.

###################

What I would do, to get around this whole mess is either:

  • Use a 3D widget instead of the TextRenderer and simply get the PlayerState via that PlayerCharacter (it has a pointer to it by default)
    and simply passing that to the Widget, so it can retrieve the PlayerName (I would move the PlayerName variable to the PlayerState,
    where it normally belongs to, and not as RepNotify).

OR

  • Move the PlayerName variable to the PlayerState (where it normally belongs to, also not as RepNotify) and when the PlayerCharacter respawns, getting
    the PlayerName from the PlayerState point.
    – The issue here is, that you need to be sure, that the PlayerState already replicated the PlayerName and that is not the best thing to do.

OR

  • Move the PlayerName variable to the PlayerState (where it belongs to), have it still as a RepNotify, and then updating everything that wants to know
    about the change via the OnRep. Best idea would be to add an EventDispatcher here, where other Actors can register themselves too
    – This also comes with the issue of replication speed. If the PlayerCharacter get spawned AFTER the variable is replicated, the OnRep will have a nullptr
    for the PlayerCharacter and it won’t set it until the next call

###################

So the best idea, for me, is to use the 3D Widget and bind the value to it with the PlayerState.

EDIT: Additional note: The PlayerState already has a PlayerName variabiel. It can be set via the GameMode function (SERVER ONLY) “Change Name”, by giving it
the PlayerController of the Player you want to change the name of.
You can also call a console command “SetName NAME” to do that, iirc.

Then you don’t need a custom variable.

1 Like

With a lot of help from eXi, I’ve decided the whole setup is too broken and I’m going to start again. This all should work, but doesn’t.