I'm trying to figure out if it is possible to reset the pointer of an Actor and simultaneously not make it disappear from the world.
Example:
1. auto Item = GetWorld()->SpawnActor<...>(...);
2. ...
3. Item = nullptr;
- resetting just the pointer
4. Actor is still in the world
I believe that duplicating this actor would work, but it mustn't be the best solution IMO.
Asked
Active
Viewed 1,799 times
0

Sheim
- 59
- 2
- 11
1 Answers
1
You seem to be working with the assumption that clearing a pointer will automatically destroy the Actor. Have you verified that is actually the case?
Looking at the docs, SpawnActor
just returns a regular 'dumb' pointer. In C++, resetting a plain pointer to null
does not destroy the object it references; some explicit action is probably needed, to destroy it. The UE4 article on Actor Lifecycle seems to support this as well.
This could probably take the form of resetting a smart pointer (TSharedPtr
), or calling Destroy
on the actor itself.

BTownTKD
- 7,911
- 2
- 31
- 47
-
Oh, you're right! I hadn't checked it in the World Outliner before and now as I see, the actor is still in the world, but teleports to a strange position and does some strange stuff. Thanks – Sheim Apr 26 '18 at 18:48