x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to reference each PlayerController from GameMode in Blueprints for a network multiplayer game.

I am working on an online turn-based combat game (think pokemon) and I am trying to setup the HUD for each client to show each player's stats such as health. I am also trying to set a flag on each PlayerController for whether or not it is that player's turn to attack. I am getting "Blueprint Runtime Error: Accessed None trying to read property ~" when I try to reference the second player pawn or controller. Everything works as intended on the listen server client, but not the remote client.

I was hoping that somebody could explain in a general way how to pass properties between two remote clients and how to reference the PlayerControllers for those clients from the GameMode. Thank you.

Product Version: UE 4.11
Tags:
more ▼

asked May 24 '16 at 08:43 PM in Blueprint Scripting

avatar image

Amplify91
3 1 2 3

avatar image jblaswu May 25 '16 at 05:07 PM

Odd, i was sure i posted my suggestion on the switch turn. here it is again...i use playerstate to store the variables.

alt text

switchturns.jpg (712.5 kB)
avatar image CriErr May 29 '16 at 02:40 PM

Even since question is answered, i feel need to make a remark that code on screenshot in accepted answer is kinda wrong.

The Owner (get owner function) of Player State class is appropriate Player Controller, so it always can be accessed on server or on owning client without any extra setup required.

Also if any of you need some help on blueprint multiplayer setup, msg me on forum.

avatar image jblaswu May 29 '16 at 04:25 PM

thanks, im still discovering how unreal works, so if i dont know any built-in feature, i create it to fit my needs.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

you would need to add a reference of Player controller to your player state, and from Gamestate get PlayerArray which returns the playerstates in the game, cast it and retrieve the reference.

alt text

more ▼

answered May 25 '16 at 01:29 AM

avatar image

jblaswu
813 22 11 46

avatar image Amplify91 May 29 '16 at 01:51 PM

This does actually answer my question, so I have accepted it. Thanks! However, I believe my actual problem is not what I had asked in my original question. My second player does not appear to be loading/spawning correctly and I am getting null reference trying to access it. I will post a new question if I figure out exactly what my problem is and I can't fix it. Thanks again!

avatar image jblaswu May 29 '16 at 02:00 PM

i think i got your issue. here is the gamemode setup i always bring up if i need multiplayer managment. this is from the multiplayer shootout. it assures you each spawned player has its own controlled pawn. i even make a BP for player start to keep things tidy and do an auto RcvReadyRespawn if im debugging (and dont want to wait for the onPostLogin to trigger it) alt text![alt text][2]

gmode.jpg (923.8 kB)
pstart.jpg (223.2 kB)
avatar image jblaswu May 29 '16 at 02:03 PM

please note i forgot to link the controller from onpostlogin to the rcvreadyRespawn (i adapted it for the screenshot)

avatar image Amplify91 Jun 04 '16 at 08:20 PM

Thank you for continuing to help out with this. I have been busy the last few days, so sorry I am slow with replying.

My problem seems to be that RcvReadyRespawn only fires on the server, but not the remote client. Could this be because I am just launching the level instead of using JoinSession and an OnlineSubsystem? For all my networking I have essentially copied the MultiplayerShootout example already, so you can assume my project is extremely similar. I do not call the respawn event from a custom PlayerStart. Should I? That does not seem to be the proper way to handle things. Like I said, my problem appears to be that OnPostLogin is only fired once for the listen server client and not at all for the remote client. This causes my remote client to spawn a default character at the remaining PlayerStart instead of spawning the character properly within RcvReadyRespawn.

Again, I am just PIE'ing into my level and skipping the main menu and the matchmaking create/join session stuff. I am doing this because I have not been able to get a Null or Steam OnlineSubsystem to work yet. You have been beyond helpful so far! Thank you!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

in your instance blueprint, there is an "OnPostLogin" event with the controller added in the game

more ▼

answered May 25 '16 at 09:05 AM

avatar image

mdonge
830 31 12 38

avatar image Amplify91 May 29 '16 at 01:46 PM

Thank you. I did already see the Event_OnPostLogin in my GameInstance BP gave me a reference to the player controller that is joining the session.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Late to this party, but for the benefit of whomever might be looking this up, for any PlayerState you can call GetOwner and cast it to the player controller you're using. For replication just make sure you put a SwitchHasAuthority. alt text

getpcfromgm.png (52.9 kB)
more ▼

answered Dec 31 '18 at 07:30 PM

avatar image

awesomespaceman
1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question