I'm executing the Character code twice

Hello guys.

I placed another Character in my world:

I use it for testing purposes, but it seems to create problems… for example:

I have this function that gets called at BeginPlay

Once I click the Play button, I should see two texts printed out:
“CLIENT”
“SERVER”

But for some reason, I’m also displaying the texts for the FirstPersonCharacter2

So i’m seeing:
“CLIENT”
“SERVER”
“CLIENT”
“SERVER”

That’s bad. It’s like I’m also running the code for the other character!

Why? How can I resolve?

Thanks!

Any tip??

Even when I run a multiplayer match (2 players) this happens.

If I kill the second player (or the second player kills me) the HUD gets printed on both sides.

The window I’m actually playing on should only show “You killed 123…” and the other client should see “You were killed by 456…”.

Instead, me and the other client see both messages!

Why?

I con’t get it, you seem to understand why this happening as you got 2 characters on level, BeginPlay is always executed on start of actor in play mode regardless of it’s state, other init functions like PostInitComponents are called in editor placement too, thats main diffrence with BeginPlay. I think what you seeking here is player possession by player controller (or any other controller) which will event that signfies character to become alive, you can do that by overrideing :

Thing is it is only called on server, because PlayerConteroller for security reasons exist only on server, where clients only replicate Pawn actions regardless who possess or not

How do you display those? You should direct this message to specific player, you using HUD class or UMG?

I declared two BlueprintImplementable events in the PlayerCharacter.cpp: OnPlayerKilled and OnPlayerDied.

When a player kills another, the Killer calls OnPlayerKilled event, meanwhile the victim calls OnPlayerDied

Then, these two events just update the text of a HUD Widget Blueprint Class

On the Character BeginPlay I use the Blueprint node called CREATE WIDGET and I create a new instance of the Widget Blueprint Class and add it to the viewport.

Tomorrow I will attach some screenshot, so don’t leave me alone and always take a look at this question xD

They are two Widget Blueprints: one shows “You killed…” and the other “You were killed by”.
At BeginPlay I add both to the viewport and when the two events run, they call the ChangeText() function in order to print it out on the screen the name of the killer or of the victim

So you use UMG, so how do you initialize it? The symptoms shows that you not do it per player

So you store refrence to it right, in class and for each player?

other point where things can go wrong is how you call OnPlayerDied

So something is wrong with OnPlayerDied. I think you should create HUD widget with all the stuff and create it for each local player, when you kill someone you send right messages to right players, if your own API can’t target a specific players then you gonna hit troubles like that

Actully i think i realized why this occures, the other playercharacter add widget to all clients that it has, in fact you added 4 widgets on view port 2 for each to all clients. You should check if player is local. Try to seperate HUDs for each player, add HUD only to local player

You need to remeber that server and each client will have same copy of object and each conna be excuted sepretly but they will exist in same time (or else they are specificly created only for server or specific client). The network multiplayer is to replicate state of classes in server in to the client. So what happens here each client has same 2 characters object inb memeory, they both create widget on local viewport and both trying to display message on local viewport

You should check if player is local.
What do you mean? My game is supposed to be a Multiplayer game, and this happens also when I run 2 players (1 server/1 client)

It’s kinda confusing and frustrating.
Tomorrow I’m posting screenshots of the C++ code and of the blueprints

Ok, here are the screenshots:

When the player KILLS someone and when the player GETS KILLED by someone

The events OnPlayerDied() and OnPlayerKilled()

Also, if the Client kills the server… nothing happens…
If the server kills the client, both messages appear

Also notice Server: HUD CALLED

Those messages come from the Widget Blueprints…

I would like to see what happens if you add code for movement events. You may have somehow possessed the dummy character. This would be confirmed if both characters move.

I deleted the character from the world. I’m trying it setting 2 players (1 server and 1 client) and the issue comes the same.

See below for more infos