20201022 UE4 the graph is linked to private objects

English

If you try to spawn a component in C++ using NewObject(), what you should do is to use CreateDefaultSubobject instead of it, which will solve the issue.

中文

最近写一个组件SceneComponent组件,叫它A吧。我在A的构造函数中新建了两个子StaticMeshComponent组件,其中一个是用CreateDefaultSubobject创建的S1,一个则是直接用NewObject创建的S2。

A被我写完之后,我把它挂到一个蓝图类上,然后点编译和保存,保存的时候弹出错误:

the graph is linked to private objects

Google查不出个啥,于是只能够读源码。查到源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// File: SavePackage.cpp
// Function: Save()
if( !Obj->HasAnyFlags(RF_Public) && !Obj->HasAnyFlags(RF_Transient))
{
if (!IsEventDrivenLoaderEnabledInCookedBuilds() || !TargetPlatform || !ObjPackage->HasAnyPackageFlags(PKG_CompiledIn))
{
PrivateObjects.Add(Obj);
}
}
// ...
// The graph is linked to private objects!
if (PrivateObjects.Num())
{
const FText Message = FText::Format( NSLOCTEXT("Core", "LinkedToPrivateObjectsInOtherPackage_FindCulpritQ", "Can't save {FileName}: Graph is linked to private object(s) in an external package.\nExternal Object(s):\n{ObjectNames} \nTry to find the chain of references to that object (may take some time)?"), Args );
}

也就是说当要保存的这个UObject的ObjectFlags字段有问题。断点可得它的名字,是前面创建的S2组件,以及它的ObjectFlags是0。

回到创建S1和S2的地方,继续断点。可以看到S1的ObjectFlags正常,而S0的ObjectFlags确实是0。

所以猜测是不是不能够在构造函数中使用NewObject。

修改S2的创建方法为StaticMeshComponent之后,问题解决。

Buy Me A Coffee / 捐一杯咖啡的钱
分享这篇文章~
0%
//