Destroying Foliage Instances In Multiplayer Lag Glitch

I’m working on a multiplayer game and I’m trying to destroy the foliage instance the player is looking at it, so far I have tried these 2 methods:

While the first executing the sphere trace on the server & client when destroying, and the second one only executing it on the server (from the event that calls “Remove Foliage Actor”) and using that info to remove the instance.
Both seem to be very glitchy, first one seems like it works fine in “Play In Editor”, but after packaging and trying on an actual dedicated server with players, it seems to randomly not work for the clients (like 50%, just doesn’t remove the instance for the clients, for the server it always seems to work).

Please help me figure out how to make it work.

You have a myriad of debugging options, have you tried printing out what you’re hitting instead? Start pulling off values from the hit result, and handle the case of a failed cast.

Does the foliage have simple collision?

If I had to guess you’re probably just not hitting the foliage if you’re using a sphere trace. As soon as it hits something the trace will stop. What’s to stop it from hitting the ground?

Everything seems to be working correctly. The issue is only in the packaged version of the game. In editor play mode it all works great.
The instance just doesn’t seem to be getting destroyed on the client.
Also, for some reason, after I try to destroy one instance, all the trees around it (and that tree) start to get glitched with the camera, depending on where I look they show or disappear. All of this is only in the packaged version of the game.

UPDATE: I believe my issue is being caused by the amount of foliage instances that I have, before I added all of the foliage to my level everything worked fine.
I have about 10k instances of what I’m trying to destroy. I guess it bugs everything out. Any ideas on how to fix this or a workaround?

Disclaimer, i’m not a UE4 wiz, I just like finding stuff that breaks and how to to fix it by figuring out how things work.

I’m going to open the editor and try to replicate what you have set up. I don’t know how a sphere trace works outside of the obvious. Unsure how often it does the collision check, but if it were to hit hundreds of the same thing in a single tick then it might break. Or cause an ensure, is there really nothing in your out logs or message log?

Did you try doing a sphere trace by objects instead?

Hey Tbjbu1,

I recreated from the pictures you showed a similar project. Didn’t run into any issues in PIE or a cooked build for win64. Did the same trace you did with the foliage instance static meshes, and put about 10,000 of them in the level. Does a trace between two arrows on the main player pawn, and gets rid of any foliage it hits. Maybe it’s a replication issue?

Are you testing it with a dedicated server?

No, client is the server in my setup. Which is why I think it’s probably related to replication. Not sure what it would be exactly though.