I’m sruggling for a few days now. After much try and error i got my clients to work normally (on spawn they are all rotated wrong and idk why but otherwise everything is fine). But now im completely stuck why my listen server has no controls. i searched the internet and i can’t find any working solution for this.
As you can see in the last picture where i printed the possesed pawn everything seems to posses correctly.
When i add more clients (tried up to 4) all clients are fine, just the server doesnt work (the server also gets a widget created but thats it)
BeginPlay is not a “receive controller changed” event.
On server, BeginPlay here will trigger as soon as the character is spawned, and thus before the controller possesses it, so GetController is most likely null and cast fails.
On client it’s a bit different as BeginPlay triggers after actor replication, which includes an initial bunch of variables, so it may work because Controller is part of the initial bunch.
You need to find a better place for this.
It looks like you are not even using the character/pawn for the input context, so this code has nothing to do in the character class. Move it to playercontroller class. Event BeginPlay (in PC) should be fine since you don’t need anything else than the playercontroller itself.
I have to admit that the black comment is actually the one that came with the default first person controller when i imported it.
Through a tip on reddit i took a another look at the character again and changed the “get controller” node to a “get player controller” node (jus some try and error with no real plan) and now it works for some reason, but when reading some tips from others im slowly getting confused why it works now
I also tried to use a delay loop in the BeginPlay before it casts to the controller but that didnt work.
Conclusion: it now works but i have to take a look again and try to understand why it works.
Also since u mentioned to put it in the PC class…
… I also have most of the specific inputs in my characters since im packaging this project (archviz) for windows, mobile (android) and VR. when my controller gets created it first checks if a HMD is connected and then posseses the corresponding character/pawn (VR Pawn or first person character). So my VRPawn and my FirstPersonCharacter use the same controller and the possesion is just based on what plattform the app is started on. Thats primarely the reason why i didn’t want to put to much keybinds etc that are just specific to vr or pc/mobile into the player controller (tho i dont really know if that makes much sense… it just sounded right for me to do it like this).
im very new to programming for multiplayer and trying my best to get the hang of it
Hmm so your two different character classes are each using a different Mapping Context ? In that case I get it.
Using node GetPlayerController may work but it’s a bit wonky - That node is very different as it is a non-contextual node, not related to the character the code is executed in. It is a generic node that will find and return the first playercontroller available on the running machine. So yeah it will find the playercontroller even if it has not possessed the character yet. However, as BeginPlay runs for every character in the World, you are adding as many mapping contexts to your player controller. So I wouldn’t be surprised if you run into issues later on.
You should probably use event ReceivePlayerController instead of BeginPlay to handle this properly.