Hi, how does the Player Index work on MultiPlayer? I ask this because I set a variable on a Class BluePrint and I passed its value to the HUD BluePrint with a BluePrint Interface. The problem is that if I go on the MultiPlayer, this variable is set to everyone.
Player Index is for local multiplayer only.
If you want to keep track of players joining using blueprints, you can “listen” for them connecting in your GameState blueprint. When a new player connects to your game, they are given a player controller. If OnTick you GetAllObjectOfClass Player controller and the player controllers you get are not in your “connected players array”, you can give them a unique number, and add them to the array.
This has worked well for us so far, although we end up with one extra player controller object which we do not know where it comes from. Still, doesnt turn out to be a problem for us.
Update: An Epic person might want to chime in on performance here, when our match starts we short circuit this tick with a branch that bails immediately. I would hope this doesnt kill performance :).
Also: This is a very round about way to do this. In C++ you can deal with connected players directly. But for blueprints this is as good a solution as we have been able to come up with.
Yes, but for example, how can I see which player is overlapping an actor?
I need to get the player controller of the player who overlapped a Box, and then I need to get its HUD.
Shouldn’t you be doing that somewhat locally if you’re doing HUD related stuff with that information?
Yes, but how? That is the class blueprint of my pickup.
Sorry to interfere with this thread but would you be willing to share a picture of your blueprint for this, it will be really handy for me and my friend.
Thanks alot, much appreciated.
It’ll teach you all the basics to do stuff like that for that and he gives examples about how you could use that as a HUD
If you need help with some HUD stuff this tutorial should get you started;
Given your BP, can’t you just take “Other Actor” From the Begin Overlap Event and cast it to a player controller? Since other actor returns the actor that overlaps, you should automatically access the right one.
Where does the message display? Also try casting other actor to your own pawn / character class first.
Alright, I’m sorry my first few answers were bullshit. Now that I am home I could test a little bit and found this setup to be working for me:
Prints a string ingame “MyPlayerController_C1”, so it should be working just fine.
It works. Thanks!
So a tip - check out the Blueprint Networking Tutorials and pay particular attention to the RepNotify part of the tutorials. It’s perfect for doing things where some server gameplay thing has to notify a client to show a client-side effect/whatever.
One thing that you should look out for is network authority. If I am not mistaken the blueprint you are using is some kind of pickup item. After checking for the overlap you might want to put a “Switch has authority” node there. This ensures that the server calculates who gets the pickup and what effects are applied. If you do not take care of the authority, it will make your game vulnerable to hackers and cheaters.
Like n00854180t has mentioned, you should give the networking tutorial videos a shot. They are amazing and show you exactly how to set most common things up and what you have to look out for.
Thanks for the suggestion!
Is this correct?
You have to use the authority pin, otherwise the client still has control over the execution. Do yourself a favor and watch the networking tutorial videos carefully. Everything you need is very well explained there.