Here’s the blueprint, it’s purpose is to spawn a random weapon. It’s supposed to function similarly to a mystery box from call of duty. The spawning is working correctly, however whenever I try to destroy actor it simply does nothing.
You didn’t take the output from the spawn node. How do you know what to destroy?
The image is of the blueprint without the destroy actor bits.
I’m asking how I should destroy the actor, since every way I’ve tried to do it has failed.
If you have a reference, you can just use a ‘destroy actor’ node.
Are you getting ‘none’ errors after quitting?
Right click the return value from spawn actor, promote to variable, name it “spawned weapon” or something
Use delete actor and make the target pin your new “spawned weapon” variable
This didn’t work either. Still spawns the weapon but doesn’t delete after the delay.
No errors after quittng.
Just put this in a variable
and destroy it when you want
You mean like @tolacipeetahi mentioned?
Just to extend what was posted when calling the destroy function make sure to add an “is valid” node to check the reference of the stored weapon is set.
If you call destroy on an empty reference variable, (like before the randomization process) you will get an error.
I tried an is valid and and is valid?. For the is valid I added a branch and said if true, destroy actor and print string: destroyed. If false, print string: False. For the is valid?, I said if valid destroy actor and print string: destroyed, if not valid, print string: false. Both resulted in “destroyed”. However the actor still was not destroyed.
Now I’m getting an error upon quitting. It says the weapon is not valid (pending kill or garbage)
That means you’re trying to destroy it more than once.
Can you show the code?
The code is wrong in the sense that you are spawning multiple actors in a loop, but only holding on to the currently spawned references. You will have orphaned actors laying around the level once you call the destroy. Also you are calling destroy in a loop that regards a class array → these are not actors but classes (think of it as an actor prototype) They are not instances of the weapons.
Once the loop goes over one index the variable you are trying to destroy will become invalid. That is why you need to store the spawned actors in an array and use that for the destruction process.
Edit: added in condition to not destroy while still spawning.
Not exactly sure what you use actor class in this case. It’s not set anywhere just hindering the spawn process.
It’s hard to directly test the code as I do not see the exact logic of target points.
Are they meant to be hardpoints on a larger weapon blueprint and these are just segments of the weapon or are they spawn points for random weapons?
Yeah, you’re running all the code on a loop, including the destroy
Removed everything after the SpawnActor, and added an input for destroying the actor. I also created the Spawned actors variable and added to it after the SpawnActor. Now im receiving the error: “Accessed None trying to read property CallFunc_Array_Get_Item_1” after quitting.
It would be better to screen shot the two functions. I can’t see to what extent you modified the code.
You seem to be trying to access an array element that most likely already been destroyed or is being destroyed.
Here is a video of the working version. I only added one gun class but made it add random variations internally. It would work with many classes too.
I just extracted the destroy loop function to an event to call it before the next generation of random weapons to clear the spawn points.