I am actually stuck in my multiplayer project : a bloodbowl like. I can’t make a good throwing ball system.
The first player who picks up the ball: no problem. He can throw it, but problems happen here: the player throwing the ball sees the throw correctly but the other player sees 2 balls and sometimes, none of them are following the same path viewed by the 1st player.
Other problem : The 2nd player can’t pick up the ball (by stepping on the ball and going outside the collision box). Can you help me please ?
Picking up and throwing the ball should all happen server-side.
If you don’t want to implement a complex “client predictive ball throwing” mechanic, make sure to spawn the throwing ball server-side only and replicate its location by making the ball replicated and replicate movement.
If you see 2 balls, then its most likely that one of the balls is the ball spawned by the server and got replicated, whereas the other ball is the one that got spawned client-side.
Hello @Zangdai ,
To achieve proper replication, I recommend using RepNotify. I’m not exactly sure how you’re handling it at the moment.
If you’d like, you can share the code for how you’ve implemented the ball grabbing and throwing, and I’ll help you set up the replication correctly so it works as expected on both the server and the clients.
I would also enable Always Relevant, since this option makes the actor always be considered relevant to all clients, regardless of distance, visibility, or network priority.
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)
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.
Hello, i’m back. I have a new problem. I can correctly grab and throw the ball with the first character of the first player, but after that, the next character (still the same player or 2nd player, the result will be the same) if i grab the ball, the ball is not set on the socket location, but on the ground in a certain distance. The ball still follow the character but is on the ground. I don’t understand why
I think the issue might be that the Root Component of the ball Blueprint isn’t replicating correctly.
Do you have replication properly configured for both the actor and the root component?
If the above is correctly configured, could you send me how you currently have it set up so far? That way I can review it and see where it might be failing.
Player Controller is my personnal PlayerController i made, called “Bp PlayerControllerMultiplayer” . The “Selected Location” store where i clicked with my mouse (used to move character) and is here :
Try setting the collision sphere as the Root Component. It’s very likely the issue is happening because the current root isn’t handling collision properly