Basically, I have a GameMode which has the MainPlayerController as the PlayerControllerClass, as follows:
As you can see, there’s no
Default Pawn Class because the MainPlayerController is the one responsible for spawning the character into the world. And this is how I do it:
Though the BP seems confusing, what it does is pretty simple: On BeginPlay, the Server spawns the character in a random location.
One important thing to note here is that I’m passing the MainPlayerController as the owner of the character. This is because I’ve read a lot about ownership and replication and seems only characters owned by clients (which are, per say, controllers) can run an RPC
Run On Server.
My Character, which is Character_Main, has a function called Add Item To Inventory. This function basically executes when the player clicks on an item which is in range with the character.
Also, this Add Item To Inventory function is the one responsible to call an Event that’ll only occur in the server. Contextually speaking, the server has to destroy the item from the “real world” and afterward transmit this information to all the other connected clients.
My misfortune here is that this event that only should be run on the server is not being called. This is how Add Item To Inventory is implemented:
Currently, I’m debugging the game running the server as a dedicated one instead of p2p. But if I unmark the option
Run as a dedicated server, the server character is able to run this event seamlessly.
THINGS TO KEEP IN MIND:
- I’ve tried to put a
Print Stringwith the
Display Nameof the owner of the character and it displays the expected value, which is
- The owner of my character is
MainPlayerController, but it is possessed by an
AIController. This is a TopDown game and I found no option if not doing this because of the movement replication (ideas are welcomed).
So, my final question is: what am I doing wrong?