How to call the parent desctructor? (Actor Component)

I want to override the destructor of a actor component. But i don’t know how to execute the parent destructor in this case.

UMyActorComponent::~UMyActorComponent() 
{
	Super::~UGameStateComponent(); //--> Crash
}

How to do it?

Thank you so much!!

ok… I’m hoping that in this case unreal C++ works the same as standard C++.

https://en.cppreference.com/w/cpp/language/override

If not, please let me know.

Don’t do that.
Virtual destructors automatically calls parent(s) destructor

1 Like

Thank you very much for confirming it… sometimes I am very confused with the way unreal works.

Virtual Destructors is a general C++ thing and has nothing to do with Unreal Engine specifically.

However UObjects have their own garbage collection so by the time you reach the C++ Destructor it might be too late and you end up with dangling references.

You should probably override BeginDestroy instead if you need to clean things up manually before the Garbage Collector takes care of the rest.

2 Likes

I’ll use BeginDestroy instead of destructors.
Thank you very much for the information

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.