Is there really no way to know when an actor is destroyed? Only workaround I’ve found is OnDeactivated and to deactivate the component before destroying it. That’s not exactly ideal, but will work for the time being. I’m just curious if I’m doing something wrong here or if there really isn’t a OnDestroyed event for actor components.
I think you misunderstood what I was asking. I need Actor Component A to know when Actor Component B is destroyed. There’s an event I can bind to for Actors themselves, but Actor Components have no such event. The only event I can bind to is Activate and Deactivate, which is what I’m using for now by first deactivating the component before I destroy it.
You will need to dispatch from Event End Play and listen to it in another component.
You can’t bind to End Play for an Actor Component. I know I can use a custom event dispatcher as well, but I don’t want to as I’m working with generic Actor Components. Component A that spawned Component B doesn’t know what Component B is and doesn’t need to know what Component B is and I don’t want to hard reference by casting just to find out. OnDestroyed would work fine, but Actor Components have no such event exposed to Blueprint (seams like they have this event in C++ though).
As above, have the End Play call a dispatcher you bind to. The delegate you’re looking for does not exist in BPs, afaik.
Whichever method you’re using to destroy componentB. Instead of calling that could you call a custom event within componentA which destroys componentB and then does what you need it to?
Often it’s the actor that owns the component that gets destroyed and we want to listen to the component being released as it happens.
Nope, I need some clean up logic to happen regardless of how something is destroyed. With OnDestroy for example on Actors it doesn’t matter what destroys the actor I’ll be able to process my cleanup logic. This doesn’t seam to exist for Actor Components.
None of your suggestions are valid. You’re not understanding what I’m saying. I cannot use a delegate. Component A and Component B have no idea what each other are. They’re added dynamically at runtime.
It works with dynamically spawned components. Did you even try?
And yes, you can have the delegate execute in another entity, too. And no, they do not need to reference or be referenced, or know about one another’s existence:
When the New Blueprint 1
component gets destroyed, the Some Other Component
gets a notify.
My solution of using OnDeactivate works fine. While it’d be more ideal for Unreal to have an OnDestroy for Actor Components this will work.
It will not work. Component A needs to listen for Component B to be destroyed. Component A only knows that Component B is an Actor Component it does not know anything specific about it. I do not want to cast it and create a hard reference to it either. There is no OnDestroyed event to bind to for Actor Components. There is only Activate and Deactivate.
That only works if Component A is aware of what Component B is. You’re not reading my replies. Please stop making this suggestion. I know how delegates work when classes are aware of one another. These are not. There is no NATIVE event for components OnDestroy in BP. It only exists in C++.
Your screenshot is literally creating a hard reference to New Blueprint 1.
That is again literally a hard reference to New Blueprint 1 and now also Some Other Component. I am aware I can do this if I hard reference. I do not want to hard reference.
Below is a non-hard referencing Actor Component add and is what I’m utilizing to handle this properly.
My post was purely to see if I was missing something as to why the OnDestroy event wasn’t available in BP for actor components since it does exist.
This is 100% what’s in the last pic.
That only works if Component A is aware of what Component B is. You’re not reading my replies.
Use inheritance, work it into the base class → Cast. You’d cast to your base class here which would return the correct type when adding componment since it’s propagated:
Good luck. Tapping out, as suggested.
Just stop. You’re not even reading what I’m saying. Please go bother someone else.
For anyone with this problem my solution is as follows.
Use OnDeactivate event of the Actor Component. Set the Actor Component to Auto Activate. Now in the Actor Component in Event EndPlay first Deactivate the component. You can now run your anonymous logic as needed.
Unfortunately the Actor Component OnComponentDestroyed C++ logic isn’t exposed to BP.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.