SpawnActor method adds spawned actor to Actors collection in your Level. This means that it can be garbage collected. Calling Destroy is enough, this method sets bPendingKillPending flag. This means that this object can be available for some time until GC destroy it. To check if object is in pending kill state, use IsValid() method.
Cheers!
Assuming I dynamically created and spawned an actor during runtime:
AFoliageCluster* cluster = world->SpawnActor<AFoliageCluster>(location, FRotator(), spawnParams);
How do I destroy and delete this actor properly after it should no longer be used? I used the Destroy method for that, but is this enough? Do actors that get dynamically spawned during runtime and are no UProperties garbage collected??
So the question is, do I have to call this after I made sure the destruction process initiated with the Destroy() call is finished:
delete cluster;
?
Actually, there is also MarkPendingKill() method called. This means that RF_PendingKill flag is set, that’s direct reason why IsValid() returns false;