I am trying to make a multiplayer car enter/exit system. The server can possess the car but when I try to possess the client to the car, it doesn’t work. What am I doing wrong in these screenshots?
Using the index based statics on a server is bad practice and will very often give you results that you don’t expect
On the server, all controllers exist, which means you can get any controller through the index, for any player connected
On clients on the other hand, only the owning player’s controller exists, so getting the controller at index 0 will return your own controller, but that’s misleading and can be confusing
On listen servers, the server’s controller is at index 0, and the other clients’ controllers are after that
What that means is that when you call GetPlayerController(0) on a listen server, it will always return the server’s controller
In your case, since your RPC is on a controller, when the function gets called on the server (since it’s a server RPC), it will run on the server’s version of the correct controller. So since you know that you’re on the correct controller, you can then use GetControlledPawn() to get the controller’s pawn, not GetPlayerPawn(0), since that would return the Listen Server’s pawn on LS, or the first connected player’s pawn on a dedicated server, which is likely to not be the pawn that you want to access
Well, thank you a lot for your suggestions. You provided me with an understanding of not using index based statistics. So I made some changes but I am not sure that I did it correctly. It keeps not possessing the client. I am sorry if I missed anything that you suggest. What should I change according to the screenshots below? Thank you for your answers.
You don’t need the CarCall function, you can call CarServer directly
You should add an input to CarServer of type Pawn perhaps (or maybe your car’s type), and then in your character bp you should call the CarServer on its controller as you are doing now, and pass the Car to it via the newly added input
Then in your CarServer, all you have to do is call Possess. Leave Target unconnected (it will default to self), and connect the input of CarServer to InPawn of Possess
However keep in mind that this will unpossess your ThirdPersonCharacter, so it won’t be able to handle any more inputs