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"

Get player ID from character blueprint.

Hey guys,

I have a Ball Blueprint which takes some parameters. One of them is the Player ID, that spawns the ball.

Here's my setup in the character blueprint:

alt text

This is my level blueprint:

alt text

The problem is, that when the server spawns the ball, when the event fires in the Level BP, it increments all "Points" variables of every player, including itself.

When the client spawns the ball and the the event fires in the Level BP, it increments all "Points" variables of all players, except the server.

Why is this happening? Doesn't the PlayerState hold dfferent Player IDs for each player? Or is it because I'm calling it from the Character BP?

I've been trying to solve this 2 days in a row... No luck. Any help is appreciated.


Product Version: UE 4.11
ball_spawn.png (337.3 kB)
level_bp.png (147.3 kB)
more ▼

asked Jun 02 '16 at 04:05 PM in Blueprint Scripting

avatar image

7 4 4 5

avatar image emperor_katax Aug 17 '18 at 11:05 AM

I figure it out this way and its working fine: I add “TextRender” component to my third person character. alt text

Then I used “PlayerState” variable which exists in Pawn as variable and it gets updated on all clients. This PlayerState provides a couple of useful variables like “Player ID” which again, is updated on all clients and it “is” unique.

alt text

So I put this in my TextRender on my character, here is the result.

alt text

Then I assign Z key to set text box to a string as text, so when a player hit Z key, the TextRender will change from client ID to a string and, it will be visible on each client. For this functionality, I did:

A- make and call an event on the server to send PlayerID to server

alt text

B- make and call another event to send PlayerID again, but this time send that PlayerID as “Multicast”.

alt text

sc-00.jpg (250.9 kB)
sc-06.jpg (237.2 kB)
sc-01.jpg (263.7 kB)
sc-02.jpg (286.7 kB)
sc-03.jpg (286.8 kB)
avatar image emperor_katax Aug 17 '18 at 11:07 AM

C- then, compare PlayerID, which I received, by PlayerID that I have from “PlayerState”. If these two are equal, TextRender will print the text on each client.

alt text

After running 3 clients (and make then sorted on camera!) , I chose Client 1, and pressed Z, the string only comes up on client id 263.

alt text

sc-04.jpg (280.2 kB)
sc-05.jpg (295.8 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

i got a way that is a little more redundant (client executes logic to himself, trigger the event on server (along with his playerId), server to replicate all, replicate all compares to playerId and excludes if the Id is the same as initiator) but using switch has authority basically so in theory, the problem isnt there (i assume you got your spawn ball working everywhere). so yes, you might be doing something wrong on the level blueprint, not because it is IN the level blueprint but the logic that triggers it. could you post a slightly bigger screenshot of it please?

more ▼

answered Jun 02 '16 at 04:19 PM

avatar image

813 22 11 46

avatar image Cosma_One Jun 02 '16 at 04:23 PM

sure here it is:

alt text

level_bp_rest.png (155.2 kB)
avatar image jblaswu Jun 02 '16 at 07:31 PM

i dont think that overlap is communicating with the server at any point. what i would do is after the BeginOverlap is fired, send OtherActor to the server (Add custom event, Replicate On Server). After that, the server adds the point to the Points Variable and that variable should be Replicated. once the server does the change on the variable, it should be updated to every player...it confuses me that you are firing the event on the map level. why dont you make the trigger a BP and code it from there?

avatar image Cosma_One Jun 02 '16 at 08:01 PM

I did tried to make the trigger a BP, but I was faced with the same problem, I can't update the clients individually. How can it be done from there?

avatar image jblaswu Jun 02 '16 at 08:05 PM

you tried sending it to a ReplicateOnServer? post the new screenshot. also remember to select Replicated on the int variable Points

avatar image Cosma_One Jun 02 '16 at 08:20 PM

how would the server know, when replicating, which player's points to increment? If I use the PlayerID variable that I have in my Ball, it won't work because the playerId is always the servers for some reason. When I get it before replication, it displays the client ID, when I replicate it, it shows the server ID, even though I sent it the client ID when I fired the SpawnBall event, which is replicated to server(first image in the post)... It got me pulling my hair out. Unless there is another way to incement the points for each player without using their ID, which so far, it eludes me.

avatar image jblaswu Jun 02 '16 at 09:02 PM

you have to set on replicated on the playerid on the ball too

avatar image jblaswu Jun 02 '16 at 09:19 PM

this is a very simple example. try to copy it and check if it works. hopefully i could catch my point with the screenshots...you spawn a ball (it has a box collision component). anytime you walk into the box collision, it will detect you, announce the playerId stored, tell the server to add a point to the overlapped actor and the server announces the new score.

now, i know you dont have a reference to the overlapped actor but you got the playerId stored on the ball (which im trying to make a point on my screenshots, showing that the variable is being passed). you can do a gamestate->get player array and a for loop to compare each playerstate the array gives and compare it to the playerId. alt text

untitled.jpg (1.4 MB)
avatar image Cosma_One Jun 02 '16 at 10:54 PM

will try it tommorow and let you know

avatar image Cosma_One Jun 03 '16 at 11:00 AM

I tried to copy it, and when I was getting the player ID -> PlayerCharacter -> Cast to FirstPersonCharacter, the cast was always failing and I was wondering why... And then I say to myself... Hmmmmm when I create the Get Player Character Node, it wants a Player Index.. I was feeding that player Index with the PlayerID, which I thought that was the correct way... But then I say "What if instead of the PlayerID, I sent it the Index in the PlayerState Array in which it was found"...... GUESS WHAT.... IT WORKED. IT WORKED GOD DAMMIT.

This was the reason from the very start that my program didnt work.. I was feeding it the PlayerID in the Player Index instead of the actual index in the playerstate array.... NOONE TOLD ME THAT THESE TWO WERE DIFFERENT. COME ON GUYS.

This is very crucial. Everyone says "Its ok, just get the player ID and then get his character".. THIS IS VERY MISLEADING.


Phew, that was...mmm... refreshing... Anyway thank you very much for your help... I really appreciate it... Stay safe.

avatar image emperor_katax Jul 19 '18 at 01:55 PM

... dude, can you put your final blueprint here ... i experience same issue... need a unique ID of player.

avatar image ilias48rus Jul 27 '18 at 08:07 PM

If i understood correctly the thread says that you should use "find" in gameState\"get player array"(node) to get "player id" (which you ,for example ,can use for "Get Player Character" node)

avatar image emperor_katax Aug 18 '18 at 02:20 PM

... check my latest comment ..... ; ] ,,,

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

This is unbelievable, this thread is ONY ONE place that says way to get id to use in getPlayerController|Character nodes, which is really often used ones while u.e. have at least 3 different ids which named “player’s”.

more ▼

answered Mar 24 '18 at 07:52 PM

avatar image

25 3 4 6

(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