Destroying one actor with multiple copies

Hey,

I am trying to make an ability in my game where you can spawn in three of an object and when you spawn in the forth, it automatically deletes the first, and so on and so forth. Currently, I am able to delete one. However, after I get the error “Blueprint Runtime Error: “Attempted to access BP_SpawnablePlatform_C_1 via property SpawnablePlatRef, but BP_SpawnablePlatform_C_1 is not valid (pending kill or garbage)”. Node: Destroy Actor Graph: Spawn Platform Function: Spawn Platform Blueprint: BP_FirstPersonCharacter”. I figure this is because the call to destroy actor does not know what to target but I was wondering if there is a way to fix this.

Here is a photo:

add your platforms to an array, when its full (length = 3 platforms) get index 0, destroy actor, remove index 0.

this will remove the first platform and add the latest one last

2 Likes

I am sorry. I am pretty new to unreal and have never used arrays. Could you explain how to do this? I made an object array and made 3 indexs with each one being a refrence to bP_spawnable platform, but I get the feeling this was incorrect.

you dont need to add index’s, just grab the array and use the add node.
the array should be of type actor so you can use the destroy actor node on it later.

encapsulate the pseudo code above to remove the first platform.

if you need more help show me your code so i know exactly where you are at

Alright, I will try it in the morning and let you know.

I’ve been working on it but don’t fully get it. I have to go to work so I’ll try later today or early tomorrow and get back to you. Sorry about all the delays.

So it seems to be working but I am getting the error: Blueprint Runtime Error: “Accessed None trying to read property CallFunc_Array_Get_Item”. Node: Destroy Actor Graph: EventGraph Function: Execute Ubergraph BP First Person Character Blueprint: BP_FirstPersonCharacter. I know it has to do with the fact that index 0 is empty at the start, but I am not sure how to fix it because everything seems to be working other than that. Here is the graph below:

well you only want to destroy a platform when its full right?

full defined by you as X platforms

so before you call DestroyPlatform check if the length of the array = whatever X is for you

Yeah, I’m doing that right before I call the action here:

The platforms are deleting themselves properly but I’m getting the error code form above.

I just fixed it. I was being dumb. Thank you so much for the help.