UE4 将 Actor 指针设置为 null 而不会在世界中销毁它

UE4 set Actor pointer to null without destroying it in the world

我想弄清楚是否可以重置 Actor 的指针,同时不让它从世界中消失。
示例:
1. auto Item = GetWorld()->SpawnActor<...>(...);
2. ...
3. Item = nullptr;- 只重置指针
4.演员尚在人间
我相信复制这个 actor 是可行的,但在我看来,这一定不是最佳解决方案。

您似乎假设清除指针会自动销毁 Actor。您是否验证过确实如此?

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 似乎也支持这一点。

这可能采取重置 smart pointer (TSharedPtr) 或调用 actor 本身的 Destroy 的形式。