Hi ! I want to have a User Interface where the player can see his health etc. First i tried setting up the UMG widget in the Begin Play of the Player. This worked fine until i realized that every player gets a UMG widget too. Meaning every player has 2 of the exact same widgets on top of the other. I tried spawning the widgets localy using the Is Local controlled node. This has the result that only the Server got a widget but not the clients. I also tried spawning the widgets in the gamemode blueprint. This dosent work ether because the UserInterface Widget needs a reference to the player. And get owner just returns null on the clients. So what else can i do ? Or am i doing something wrong here ?
We first need to talk in the same language, by default, there is no âPlayer Blueprintâ, you might be talking about PlayerControllerâŚ
Before we can help you further, check this prior getting into Replication, it was very helpful for me:
(The site seems to be down right now, you can check later on) https://wiki.unrealengine.com/Replication
I donât know what are you talking about with UserInterface and Inventory, please use the Class names rather than your variable names
I actually hit a similar issue recently when setting up multiplayer. What I found was that I wasnât calling the âPost Loginâ event on the correct player controller, which resulted in just the server/no clients receiving the events events.
You have a slightly different Post Login setup (I used a similar setup to the Multiplayer Shootout example project), but I would suggest to make sure you have the correct target reference (E.g. Print the player controller you are calling to right before you call the event) when you make the Post login Event call. You could also use the blueprint debugging tools and possibly put an âon keyâ event in your player controller to also run the same post login code and see if that works for each client. If that works you now know that it could be the calling function, and can continue to narrow down where the issue is occurring from there.
Spawning the UMG Widgets worked now. The problem is that i need a reference for the player(My Player Character the one you controll in the networked game.). The problem is that i tried to use the âGet Owning Playerâ and then getting the Player pawn and then casting it to my Player Blueprint. But this only works for the Server
âEventPostLoginâ is in the GameMode Class. The GameMode does not exist on the Client! So the âSwitchHasAuthorityâ will only be Authority and can be deleted anyway.
Second:
UI only exists on Clients and ListenHosts (which are Server and Client). You donât want a Dedicated Server to have UI.
Third:
When you want to display something about the local PlayerCharacter, why not using âGetPlayerCharacter 0â?
âGetOwningPlayerâ should also work, since you passed that when creating the Widget. You just need to remember that this is all
happening on the Client. If you just want to get Data about the Players Character (the one sitting on front of the Screen, not the other Players):
Well, not really a âtipâ, but before hopping into Multiplayer Games, you should really learn the Unreal Network Framework.
It is really important to know which classes exist on which âplayersâ (Client/Server) and what they are meant for.
While itâs relatively easy to use all these classes for a singleplayer game, it is way harder to create a multiplayer game without
knowing.
Also, you need to know about ownership. Itâs pretty important to know how the ownership works and what you need to consider.
An example, which i always hit myself with, is: When the Server Spawns an actor⌠or better, when you place a networked actor in the world,
for example a door, and you want the player to open it, then you would normally enable his input somehow and call an RPC with âRunOnServerâ
INSIDE of the Door Blueprint. But that wonât work (Check link above). A âRunOnServerâ RPC only works if the Client OWNS the actor.
Actors that the client owns is for example the PlayerController. You could pass the Clients PlayerController as an owner when SPAWNING an actor.
But then only this specific client can call RPCs on the Actor. So you see, itâs not that easy. Itâs more easy to get lost in problems that one doesnât
understand when networking. Because the code for that door will compile completely fine, but the RPC will never be called and if you donât know
why, you will spend a lot of your time asking yourself why.