Hello everyone.
In my multiplayer game, I want to delete left over objects once a game round is over. I’m looking to make a garbage collector per se.
I’ve already written one, but it does not work. The way it works is rather simple:
(1) All weapons/actors that are a target for GC must be fully replicated and get spawned by the server, upon spawn, they are added to an array that contains objects that will be deleted by the GC system.
(2) The game state, which holds the GC code since it exists everywhere. We ensure that we are in a server context, then add it to our server’s GC removal array.
(3) When a round ends in our game mode, we trigger a call for the server to destroy GC objects in our game state.
(4) Then, the server cycles through each object in the array, and if they are valid, they get destroyed. Clearing the list after a few seconds.
Note that the specific custom event here isn’t explicitly in the server context since it is re-used by a local version for debree and other visual effects, however, we originally fire it in the server context and thus this event will be in that context too.
On paper, based on my understanding of Unreal’s networking, this setup should work. If the server deletes a replicated actor, it will be deleted across all clients. While doing it via a multicast could cause memory issues as the server could ask to delete objects that are supposed to be replicated but were deleted on the client-side for that specific client.
However, this set up does not work. If an object is created by the listen server’s client, it will never be deleted. While objects dropped by clients do get deleted. I have no idea why, I have tried many things over the week, but nothing seems to work.
If anyone could point out the error in my ways, I would be very appreciative.