Hello again @Zangdai ,
I’m leaving you how you should handle the replication topic, with the difference that I already have the the ball placed in the scene, and I throw it when I press a key, which is an Input Action (IA_Throw), because I don’t have the UI system that you have implemented. Also, in this code you’re only allowed to have one ball in your hand, and it won’t let you grab another if you already have one.
First of all, I recommend moving the grabbing and throwing code to the ball. Nodes like Attach, Set Actor Relative, Add Impulse and Detach should replicate by themselves.
Then, in BP_Ball make sure to enable the replication options I mentioned before
and in the Root Component set the collision to Custom, set Collision Enabled to Query and Physics, and enable Component Replicates. Also disable collisions on the mesh (No collision)
Then, to enable and disable collisions, create a bool variable and set it to RepNotify.
After that, you set it to true or false depending on the events, which will be normal Custom Events without replication. In each of those events, create an input of type BP_Character, both to use it as the parent for the Attach and for the direction or force of the Add Impulse.
Next, in your BP_Character create two variables: one bool (bHasBall) and one BP_Ball reference (CurrentBallInHand). Then create two Custom Events with the following logic, which set which ball the character has in hand and whether they have one or not. In this case, the grab ball event doesn’t replicate because the Capsule Component already replicates.
The other event, called Server_ThrowBall, does need to be Run On Server and Reliable, since it’s called through an Input Action and that doesn’t replicate. So in IA_Throw, if the character has the ball (bHasBall is true), you can throw it
And when it’s created in your case , in my case, like I mentioned before, when the Character overlaps with the ball , there you create a Has Authority so it’s handled correctly. (This Has Authority is used to make sure that logic runs on the server side, which is the one that has real authority over replicated actors. This way you avoid possible issues if both players try to grab the same ball at the same time). So only if it has Authority do you allow the character to grab the ball, and only if they don’t already have one in their hand.
I’m also leaving you some documentation that might be useful for you
Let me know if it worked for you, and if not, I’ll see about creating a simple UI to help you get it working.
Happy coding!



