Hello peeps!
I have an Actor class that has a Tmap array with a UActorComponent as its value.
UPROPERTY(VisibleAnywhere, Category = "Setup")
TMap<int32, UMyActorComponent*> activeActorComponents;
When I create an element I am using
UMyActorComponent* newComp = NewObject<UMyActorComponent>(this, UMyActorComponent::StaticClass());
if (newComp )
{
newComp ->RegisterComponent();
activeActorComponents.Add(someIndex, newComp );
}
I add 1000 elements and their names are Comp_0, Comp_1,Comp_2 etc, and when I use this to delete the elements
activeActorComponents.Remove(someIndexToRemove);
The elements get removed, but the they still exist in memory.
And when I empty ALL elements and add one again, its name isn’t Comp_0, it’s Comp_1001.
I have been trying things like
activeActorComponents.FindRef(someIndexToRemove)->ConditionalBeginDestroy();
activeActorComponents.FindRef(someIndexToRemove)->BeginDestroy();
and the elements turn to null, but the memory isn’t freed and the names still increment from the last array length.
How do I properly release the Actor components from memory?
Thanks for any tips!