之前遇到一个问题,在某个函数中使用TSharedPtr
来管理一个UObject
,待跳出函数的时候(定义域结束),报了很奇怪的一段错误。
代码大概是这样的:
1 | void AXX::Foo() |
退出函数之后报错:
1 | Assertion failed: GetFName() == NAME_None |
不用猜它为啥会报错了,因为官方直接给了原因:TSharedPtr
不适合用在UObject以及其派生类上。用了就会有问题。
Shared Pointers are not compatible with Unreal objects (UObject and its derived classes). The Engine has a separate memory management system (see Object Handling documentation) for UObject management, and the two systems have no overlap with each other.