On actor destruction in the character blueprint, two issues have come up in different blueprints. One in the HUD class, and the other in the Player Controller class. I know the issue is with the process, once an actor is destroyed the prior blueprints still issues commands to the now destroyed unit. I’ve tried fixing this in the Character and Player Controller blueprint but can’t find a solution.
The chain is the following:
Player Controller (for inputs) → HUD (to select units) → Player Controller (move selected) → Character Class (moves, displays selection, and destroys when HP reaches zero)
Hey there @LumaraIG! When an actor is destroyed, they can still technically receive calls before garbage collection kicks in. If possible, I would wrap any functions/events that are called to or from actors that aren’t persistent (anything that will be destroyed) in IsValid checks. This will stop this issue from occurring, while also allowing you to handle failed orders.
Another recommendation would be to modify the selection array to remove any element that isn’t valid when you issue commands or create an event listener to subscribe and listen out for when those actors are destroyed and remove them from from the array.
Hey, thanks for the response! I’ve tried what you suggested with the IsValid command but still receive the error. I’ve plugged the node into every part of the code to no effect.
you have to plug the array element into the IsValid Object, you may also want to log a IsNotValid message since really this is just hiding potential errors
Thanks! That got rid of the error messages, but I noticed that the print string will still send the movement commands until I deselect the destroyed actors. I’m not sure when the garbage is collected or if it will matter. Really don’t want things to stay loaded when destroyed lol.
The garbage collector will eventually get actors once they are destroyed as long as the game tick isn’t struggling too hard at the time. You will still have to remove destroyed actors from the array. You could do this when the valid check fails if you don’t want to set up a method for listening for the deaths, then you could finish processing the array.
Great work! The only note I have is the same point Auran made, try to do any modification to the array before actually running the data, as in rare edge cases, you may run into some issues. Caching a local variable copy of the array (post modification but pre-firing of commands) should eliminate most of these edge cases, with the overhead of running two copies of usually identical data.