Multiplayer Pickup

Hi everyone. I have implemented the awesome multiplayer tutorials from Wes Bunn. Thanks Wes!!! I have now hit a problem. When I load the map I have created a coin and want to add a point to the player who collects it. I have added a new integer for score to the Player Info and have made a blueprint based on my coin.

A player can collect the coin and destroy it fine but my problem is trying to locate who picked it up. I have created a HUD with a score bound to my new variable. On begin overlap i am casting to GameplayPC and trying to call a function called add gold coin (which basically adds one to my interger variable).

From the begin overlap node to “Cast to GameplayPC” doesnt work. What am I doing wrong?

Thanks
Ben

Hey N4cerBocaj,

Here is a quick example on how I would do it:

The PickupActor is set to replicated and has a box collider that will overlap anything dynamic. The Character has a Coins int value that is set to replicated. Then, the HUD creates a UMG widget that gets access to the Character and then the coins, to display it on the screen.

Thanks, this all works but I still have a problem…I don’t know how to distinguish between which player has picked up the coin. Using Wes’s tutorial I can get players in my map. But when a player picks up a coin - the HUD updates on all players. Likewise I want to set up trigger boxes so that when only one certain character enters it does something. I do not know how to reference the different multiplayer characters in gameplay. For example when ‘Frosty’ enters a trigger box I want a message to appear on his display only and destroy an actor. I can’t for the life of me work out how to reference just once character or not update everyone’s HUD…thanks (hope this makes sense)

I am not sure why you would have that issue with what I posted. In the OnComponentBeginOverlap, it gets “OtherActor” which is casted into a FirstPersonCharacter (or whatever Character you are using). If it really is a Character that is overlapping the collision for the pickup, the cast will succeed and only update the Coins for that one Character, as that is the only one overlapping the coin.

Im not sure why its working other than in Wes’ tutorials it casts to the ‘Gameplay PC’ as the player controller. Because multiple characters spawn as Gameplay PC (each with a different Mesh) the blueprint can’t distinguish which character it was as they are all Gameplay PC. My only other thought which I havent tried yet was to Cast to Gameplay PC and off that check which character it is (by breaking Player Info and getting the Character class). This would require every player having their own HUD. Would this seem reasonable??
Thanks
Ben

That still doesn’t make any sense. Just because there is a class that is used multiple times, it doesnt mean that the Overlap function would get multiple references to them. The overlap only gets the one reference through OtherActor; it doesn’t care about a name of the class when that happens, only that the Actor has overlapped the collider.

Can you show me what you are doing with your project? My guess is that you are using a multicast function or replicating something to all clients, causing the issue.

Thanks.

Thanks I got it to work. I basically created four HUDs (one for each Character class). Then when the overlap happens my script checks which character hit the trigger and sends a message to that particular HUD to add one to the score.

Thank you for your answer - what you wrote was correct but my issue was each player seemed to be sharing the same value as a score so when a coin was picked up it added to the integer “score” on everyone.