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"

Accessed to none trying to read property My Player Reference on the other player

I have a replication issue. The variable GhostLife shows at the Widget: LifeWidget in Player 1, but not in Player 2. GhostLife variable is located in Player1 (Ghost). When I play, the variable is shown as a text (100) correctly, but Player2 doesn't detect the variable.

Ingame: http://prntscr.com/jvnvsv

Error: http://prntscr.com/jvnwkp

Event construct: http://prntscr.com/jvnx3c

GetText: http://prntscr.com/jvnxby

Variable settings: http://prntscr.com/jvnxh6

Also Player2 and Player1 have replication settings to on.

Player2 spawns at runtime. Player1 is on the level when the level is opened. (Player1 is who im trying to reference and it haves the variable GhostLife)

Product Version: UE 4.19
more ▼

asked Jun 16 '18 at 02:27 PM in Blueprint Scripting

avatar image

28 4 7 14

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

2 answers: sort voted first

In your widget's get text function it refers to MyCharacter. MyCharacter is always set based on playercontroller 0. This is fine on individual devices but on the server this will tell it to use the same player for all.

So i suggest on widget constructor you instead reference OwningPlayer instead of PlayerController 0

more ▼

answered Jun 16 '18 at 03:22 PM

avatar image

3.7k 18 23 20

avatar image Pataxu Jun 16 '18 at 05:44 PM


How I can reference OwningPlayer instead of PlayerController 0? Tried by different ways, but anything work. You mean something different than what I've do in the image, but I don't known what.

avatar image mightyenigma Jun 16 '18 at 09:18 PM

That is almost correct. GetOwningPlayer gets a playercontroller. Get the Controlled pawn from the controller and cast to your character class and that should work.

avatar image Pataxu Jun 16 '18 at 09:44 PM


Still doesn't working. I don't known how to do it, I didn't understood correctly.

avatar image mightyenigma Jun 17 '18 at 04:51 AM

no errors but still doesnt work?

avatar image Pataxu Jun 17 '18 at 06:25 AM
avatar image level2 Jun 22 '18 at 02:00 PM

If you use get owning player on the player 2 you will always get the pawn of the second player. You should use a game state to get a reference to a specific player. Also the variable on your character might not be always updated to the client (Read on the network dormancy if you want to understand why). My suggestion would be to move your ghost health on a player state or maybe even on the game state.

avatar image Pataxu Jun 22 '18 at 05:09 PM

Ok, thanks. But... What I should put in 'Object' on Cast to Player State?

avatar image mightyenigma Jun 22 '18 at 06:44 PM

Gamestate gas Player Array has Player States which can be cast to your Player State class.

Remember you can only cast to classes that have a common ancestor AFAIK.

Alternatively you can Get Player Controller 1 (instead of zero) and from the get PlayerState and cast that to your Playerstate child class to access the variables you made up.

avatar image Pataxu Jun 22 '18 at 09:03 PM
avatar image mightyenigma Jun 22 '18 at 09:40 PM

Is this over network or is it local (same device) multiplayer?

avatar image mightyenigma Jun 22 '18 at 09:42 PM

You may need to wait until the PlayerState itself calls BeginPlay, and set the var from there. Many things can start executing before a PlayerState starts to exist for any given Player.

avatar image Pataxu Jun 22 '18 at 10:02 PM

Network multiplayer.

How I can do that? Im pretty new to UE4, sorry, i'm really confused right now.

avatar image level2 Jun 26 '18 at 12:18 AM

In a networked multiplayer environnement only the server has all the controllers. The client has only his locally controlled controllers. So to put it simply in your context the player 2 don't have access to the controller of the first player.

avatar image Pataxu Jun 26 '18 at 11:08 AM

How I can do it? Setting a Player Controller 1?

avatar image mightyenigma Jun 26 '18 at 03:07 PM

No, you have to use something that's not a Player Controller to store and replicate the information, like a PlayerState for example. That's one option that can work.

avatar image Pataxu Jun 28 '18 at 08:02 AM

Ok, problem solved :D

Instead of creating a reference to the Player State in event construct (Wich only happens on server, that's the reason why player 2 can't detect the reference), I've casted directly the PlayerState in the GetText_0, and I got the GhostLife variable.

The problem now is that the server and client variables are unsync, for example if I hit the Ghost on the server will rest 1 of life but in client 2, but seems easy to fix.

avatar image mightyenigma Jun 23 '18 at 01:14 AM

that might be your problem.

On the Server, Player Controllers exist for all connected players. But on the remote Clients, the only player Controllers they can access (AFAIK) are the ones owned by the device the client is running their copy of the game on.

so you will be better off using Player states since they can be replicated from the server to all the connected clients. So you just get your game state node and the PlayerArray off of that and you can loop through all the playerstates in that array until you find the one whose PlayerID matches the one you want to display the info for.

Make sure you set your Playerstate child class blueprints' variables to be Replicated so the clients can see the changed the server makes to them. These variables can be for things like health, ammo, lives, name, etc.

avatar image Pataxu Jun 23 '18 at 07:38 AM

Doesn't work on the client and server. The error is the same: Accesed to none trying to read the reference. http://prntscr.com/jyc7yf

avatar image Pataxu Jun 26 '18 at 12:02 PM

Now I got it working ONLY ON THE CLIENT, because I forgot to set the PlayerState in the World Settings. I didn't tried yet to do yout method of looping trough all playerstates, because I... I don't know how to do it lol

avatar image mightyenigma Jun 23 '18 at 01:15 AM

Be advised that trying to do networked multiplayer makes everything 5 times more complex, so i would not try it until you learn the basics of Unreal's gameplay framework first and understand how Game Mode, Game state, game instance, player, player controller, player state, and Pawn all fit together.

avatar image Pataxu Jun 23 '18 at 07:39 AM

Yeah lol, during the making of my first project (This), my unique issues were with networking, I could have finished my game a long ago, because every network issue for me takes weeks to resolve. I should have started with a single player game.

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

I reviewed your original post and I see more clearly now.

It looks like your original approach would work except that your were trying to get the ghost player by accessing Player Controller 0 (which is always the first player on a given machine. So on your server, player controller 0 is the only player on that machine (the one you call player 1) and on the client, player controller 0 is the only player on THAT machine (the one you call player 2)

so by using player controller 0 on the remote client you are getting the pawn for player 2 as your MyCharacter instead assigning Player 1 to it. So your display on Player 2's computer will always show the ghost life value that Player 2 has, not Player 1.

To solve this, since you are (in the original post) storing ghost life as a replicated variable on Player 1's pawn, you can probably just do the following:

On the pawn's beginplay, detect if it is in the server world or the client world, and store that as a replicated variable.

In the widget constructor set a timer for every 1 or 2 seconds to trigger an event called RefreshGhost. In the event, loop through all the pawns until you find the one with that isServerPlayer variable set to true and assign that to MyCharacter. That way if the ghost pawn is ever destroyed and a new one created, the display will reassign to the new one instead of referencing the destroyed nonexistent one forever after. I use a timer because it slows things down to loop on a tick. To improve performance you can forget the timer and instead add a reliable Multicast to the pawn's OnPossess event which gets handled by the client and passes the Pawn's playerstate's PlayerId to the client which he can then loop over pawns and check playerstates until it finds the one with the matching ID and assign that to the myCharacter var. Then it doesnt have to keep checkingg. it just updates wenever a new pawn is created for the server player.

That should do it.

more ▼

answered Jun 23 '18 at 01:16 PM

avatar image

3.7k 18 23 20

avatar image Pataxu Jun 23 '18 at 02:35 PM

Thanks. But I'm stuck, I don't know what nodes to put (Yeah, im very noob, I understood you but I don't know what put to detect if it is in the server, for example. I only did that I know how to do, like the loop with event)

Event construct: http://prntscr.com/jyffy8

Begin play on Ghost (Player 1, wich haves the GhostLife): http://prntscr.com/jyfgl5

avatar image mightyenigma Jun 23 '18 at 05:44 PM

there is a boolean node called isserver that you can branch on

avatar image Pataxu Jun 23 '18 at 06:19 PM

Like this? http://prntscr.com/jyhmca

(I know, i'm very annoying, but I need to do this step by step because I'm new and If I fail in something, the rest of the system would die and I will need to explain more and more)

avatar image mightyenigma Jun 24 '18 at 01:30 AM

i am sorry i havent provided screenshots. I am usually not at my computer when i answer these :)

avatar image mightyenigma Jun 24 '18 at 01:33 AM

I saw your screenshot. That can work if you set your variable to replicate. It will be less confusing if you name the variable something different like PlayerIsOnServer. Sorry I am not sure if this will work but it seems like it should.

avatar image mightyenigma Jun 24 '18 at 01:36 AM

also you can save yourseld from having to loop through the gamestate's player array if you store a reference to the ghost player's player state after you find it the first time - you can store that in the gamestate and replicate it as well. as a shortcut.

(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