Unable to Cast to an Actor to destroy it

Hey,

So I’m trying to cast to and actor to destroy it and every time I try to cast to it, it fails.
I know it’s something simple just I’m too dumb to figure it out lol. I have tried so many things and it always fails. The actor is spawned in the world by a Spawn Actor node. So I created an event to cast to the actor to destroy it when it gets the signal but I’m unable to cast to the actor to destroy it!

Please help!

Thanks -

If it is already referenced as an Actor, you don’t need to cast to destroy it.

If you didn’t know, the cast will fail if the reference is not a parent of the class you are casting to. If the reference is null, it will of-course fail as well

DestroyActor is a function of AActor and thus all your weapons should have it (presumed your Weapon is subclass of AActor) and thus casting shouldn’t be needed.
It seems you don’t know exactly what casting does, get yourself familar with principles of inheritance and type conversion.

Sorry, I’m a bit new to casting. Can one of you provide a screen shot on how you would perform the actor to be destroyed when receiving an input?

Thanks!

The hard part is the actor isn’t even spawned in the world so I’m trying to get a reference to it when it does not even exist in the world.

You can use an event dispatcher instead: Event Dispatchers | Unreal Engine Documentation

DestroyAllWeapons can Call the event dispatcher and the weapons can Assign to the event dispatcher in their respective BPs and in the created event it destroys itself instead. Then you only need a reference to the BP where the event dispatcher was added.

When you spawn the actor, you should set the reference for the object in Weapon01testRef as the actor that was spawned. Right now your cast is failing most likely because you have no object in that reference. Also why do you have these 3 classes (Menu Character Cast, Menu character cast 02, Menu character cast 03)? Unless your characters are supposed to have different functionality, you should only need the one I’m thinking…