I have an “item” actor that has a skeletal mesh root with a collision sphere attached to it. When a player drops the item, I want it to fall to the ground using simulated physics.
I know physics doesn’t play well with networked games where the location of the ragdoll is important to gameplay, so I plan to enable physics on the item if it is falling and toggle physics simulation off after it hits the ground. That way, the location of the item is relatively consistent between all players. I am trying to prototype this in blueprints but I’m having some trouble.
I have a repnotify variable, bIsFalling, which I set to true when the player drops the item and false when it hits the ground or it is being picked up. When the repnotify fires, all clients simulate or stop simulating physics depending on whether bIsFalling.
In one scenario, the player drops the item, causing bIsFalling to be set to true, which makes the item start simulating physics. While it is falling, the player picks up the item again, setting bIsFalling to false, stopping physics simulation and attaching the item to the player’s hand. The problem is, attachment is replicated, and when bIsFalling and attachment is replicated on the same frame, the clients may not have stopped simulating physics, which makes attachment fail. This results in the item attaching to the player on the listen server, but not on clients.
That is the base of the problem and I’m wondering if anyone has had this issue before and how they fixed it, because this problem also causes numerous other issues I’m having. Basically, I need to ensure clients have stopped simulating physics before setting up an attachment on the server/authority.
One way I’ve fixed this is by adding a 0.1 second delay. I can see why this works because as far as I know, replicated variables are sent to clients in a random order on a frame-by-frame basis, so as long as I tell clients to stop simulating physics on frame 1 and set up the attachment on frame 2, it should theoretically process in the right order on clients, but I also tried this with a “Delay Until Next Tick” node, which does NOT work. I also tried using Event Tick to process an attachment after I set physics simulation off, which also doesn’t work. Why exactly does a 0.1 second delay work but “waiting till next frame” does not? It makes me worried. I plan on moving this code to C++ and I can’t really use a Delay node there in the same way.
Thanks, and let me know if I need to add more details!