I wanting to have the health variable stored in the Player controller so that when players possess another character they retain the same health variable.
but when I am trying to damage a player it only damages the Host of the listen server, but when I have the variable stored locally it works as expected
Just to clarify I’m still learning networking and replication, just leaning as i build this game. So I’m unsure on why this is happening, cause the health variable, Player controller Ref & The player controller are all replicated
So we can get some more insight, would you mind sharing the portion of your blueprints that call the player damage event and/or handle replication?
In the meantime, here is some live training that directly addresses health in a network multiplayer environment as a possible solution or insight into your issue:
Going back through my code, i noticed on the event where im calling the client to update its health on player controller i was calling it on server as well, ive changed that to run on client
It now does damage to a client but also still does damge to the Host. So doing damge to client 2 will do that same damage to host, but doing damge to host wont do damge to either Client. When Host already has damage done. When moving to damage Client 2, clients 2 will jump to same health value as Host once damaged.
I’ve also turned off the player controller replicates
On a quick look at your BP:
The first custom event rep on owning client (CR Fire) wont really do a thing.
If you are inside the player controller, what player controller are you explicitely referencing then and where do you asign it? You dont need to reference a player controller inside the player controller BP except for referencing other pcs.
Let every logic happen inside a server rep event. Just replicate the health. No multicast or rep to client needed.
Use get “owning controller” instead of indexed pc.
At most times for multiplayer you can forget about indexed pc.
I would recommend getting all your logic about damage handling into the controller instead of just using the controller as storage for health.
On damage event get owning controller and call a custom event you create for handling the damage logic - inside the controller. So you have everything centralizied. (Logic handling inside controller with server replicated custom event)
So i tried what u suggested, Moved my damage code over to PC & have a custom event that calls in character_BP on any damage. Same behaviour tho, i have an print string going on when health is decremented and it says same thing, that Host controller is being damaged.
also in Character class when I’m creating my reference to the Player controller the only node that works is an indexed “get player controller”. “Get Controller” just returns an error when a client try’s to damage
Straight out of my working research projekt. But if you cache the controller be ware that if you change the possesor of the pawn you have to handle that too.
On a Multiplayer solution the players get indexed so you are just referencing the player controller at index 0. That explains your behavior shown in the first video.
Yes i used the “Get Controller” node, it works fine when a client is damaging Host, but when client try’s to damage another client it returns the error “accessed none” on the reference to player controller, trigured on the event call after “Any Damage” node
also for the CR_DealDamage Event, how i understood it is that it was updating the clients local copy of the health variable and that SR_DealDamage was updating the server’s copy of that clients Health?
so where you meaning get rid of the event all together or just changing its replicate property?
When using the damage code I now have in player controller in the Character class with a local health variable the damage system works perfectly. but moving it to the Player controller and calling an event though a reference is where it breaks down.
Using “Get Controller” node returns an “Accessed none” error for clients & using “Get Player Controller” node only calls to damage the host?
Because any damage gets only called on server. And you casted on client before storing it into a non replicated variable (character class is owned by client iirc) at first. Just cast directly inside any damage with get controller, should fix it, or replicate the casted controller variable. I could be wrong though its 3am and i just woke up lol
I changed it a bit, so I’m still casting on event begin play but I’m now running the cast to player controller on both server & owning client through events