Storing values after Destroying actor

I have a projectile that is spawned when the player fires. The projectile creates a actor(soundTarget) when it hits a wall, then destroys itself.

The next time the player fires, the new projectile should be able to find the reference to the actor(SoundTarget) that was previously created and replace it with its own, then destroy itself again.

So a reference variable to SoundTarget should always exist, and be updated/replaced every time the player fires. But since the projectile gets destroyed, it doesn’t get maintained. I tried linking the projectile to a controller which I was hoping to use as just a repository for the reference variable, but when i call the controller at the beginning of the script it always fails. What am I doing wrong. Should I even be using a controller bp in that way?

The projectile is a pawn class, and I do have it referencing the controller.

Here is the script.

A little confused… why not just spawn the sound each time as well as the projectile? Why keep it in a variable?

Maintain the reference to the sound target in the thing that spawns the projectile?

I guess the complication comes from wanting to destroy the previous “SoundTarget” and replacing it with a new one.

The “SoundTarget” actor serves as a distraction that the enemy’s can lock onto. The player can lob something like a glass bottle, and if its inside an enemy’s sensing radius, he will go to it. If the player throws a new bottle, a new “SoundTarget” is created and the enemy should go to the new one, disregarding (destroying) the old one. I could have this grab all instances of the “SoundTarget” actor and destroy them all, but there are situations where I wouldn’t want to do that. Like if I have two enemy who I need to distract separately. It won’t work if in distracting one, I reset the other. So I need the ability to reference specific instances of the “SoundTarget” which I put into variables.

But this misses the main question. I cast a variable to the Projectile’s controller, with the hopes of grabbing it later, after this Actor destroys itself.

But when I try to get that variable back from the controller when a new projectile gets a hit response, it fails to recognize the controller. Why is it failing?

Is this any different than sending the reference to the Controller? I’ll try it, and if it works, it works. But I would still like to know why the cast to the projectile’s controller “Rock_Controller” fails every time.

The controller doesn’t get destroyed when the actorBP get destroyed, does it?

I’m not sure why the cast fails, but I think you’re overthinking the work of the projectile. You don’t need to manage the sound.

You can put the sound with the projectile and let it die ( or be killed ) naturally ( as stated above ).

This way, if the enemy is near enough they will go in the correct direction, but it wont pull enemies from further away…

The ONLY reason this would fail is if the projectile doesn’t use the “controller” type specified. To be honest this is one of the weirdest setups I have seen. You have a “projectile” that is a “pawn”?? Are you controlling this projectile? If you are “firing” a projectile unless this is some Call Of Duty drone missile you are then directing towards a target a controller has no business being a part of this process at all. You “control” a player character…if you cast to your player character controller from within the player character I bet it succeeds. Your projectile “fails” this controller every time because it isn’t using a controller…and if you set it to use one (since it is a pawn and theoretically could have one assigned) you have assigned the wrong one.