## Issue: Nested SceneComponent Does Not Show In Game

### English

If you try to make a USceneComponent class, named A, creating, encapsulating and holding a reference to another USceneComponent B, you may find that B cannot show in the game.

As we all know, when we try to add a component to Actor, we must call AttachToComponent(RootComponent) and RegisterComponent(). That’s right.

But if you make a nested USceneComponent, remind that when you add this class to an Actor, you should not only call the outer USceneComponent‘s RegisterComponent, but also the inner’s.

BTW, do not try to call the inner USceneComponent‘s RegisterComponent() in the outer’s constructor, which may cause error.

### Chinese

• B和C能显示出来了
• B和C没法跟着Actor的移动而移动
• 重新开启Editor的时候会报错，说是RegisterComponent不能在构造函数线程里调用：

if (ensure(MyOwnerWorld)) 这句话说明现在的World还没生成，或者没有Owner

## 概念区分

### AttachToComponent, AttachTo, SetupAttachment

AttachToComponent是组件绑定，绑定到父类。要在非构造函数里面使用，如果在构造函数里面使用了，会发出一个警告，并且最终实际调用的是SetupAttachment

AttachToAttachToComponent是一样的结果，看源码可以发现它实际上调用的就是AttachToComponent，但是已经deprecated，如果调用，编译器会发出警告。

SetupAttachment在构造函数中被调用，用来先标记要attach到哪个parent。

Buy Me A Coffee / 捐一杯咖啡的钱

0%
//