I am developing a multiplayer game and have created BP_Sword, which is spawned and equipped by each client. During an attack, the Anim Notify Blueprint enables and disables the capsule collision of BP_Sword. However, this causes the collision of all BP_Sword instances on different clients to be enabled simultaneously.
Currently, when BP_Sword is spawned, it is stored in an Actor variable (CurrentWeapon) inside BP_Character. In the Anim Notify, I cast to BP_Character and set the collision.
That’s all. Here are AN_HitStart and BP_Hwando (Weapon).
I discovered this issue when Character A was holding the weapon in an idle state, meaning the weapon’s collision was disabled. Meanwhile, Character B attacked BP_Enemy elsewhere. However, I noticed that the BP_Enemy that was in contact with Character A’s weapon reacted to the hit.
multiplayer seems a bit complicated at first but the simple way to think of it is everything is done on the server, the client on sends inputs. ie i want to attack now
I had to do it that way to prevent issues with weapon spawning and variable assignment on the client. So, does that mean the collision is occurring simultaneously because the weapon is not being spawned on the server?
Do not use GetPlayerCharacter(0).
On server side this will return the first character available (ie. host player or first player alive)
On clients this will return each client’s own character. This is why it enables collision for everyone.
Instead, you need to find a way to reach the character in context, ie. the character triggering this notify. I’m not sure how this is set up, but the MeshComp pin seems promising, you can probably do MeshComp->GetOwner->CastToCharacter