USceneComponentを継承したクラス:UMySceneComponentクラスのコンストラクタで、
UCapsuleComponentクラスを作り、UMySceneComponentの子にしたいです。
次のようなコードを書きました
.h
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class CATHEDRAL_API UMySceneComponent : public USceneComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UMyComponent();
UPROPERTY(VisibleAnywhere,Category = MyScene)
class UCapsuleComponent* Capsule;
};
.cpp
UMySceneComponent::UMySceneComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
Capsule = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule"));
DetectCapsule->SetupAttachment(this);
}
これをアクターにアタッチします:
.h
UPROPERTY(VisibleAnywhere)
class UMyComponent* MyComponent;
.cpp
コンストラクタ内で、
MySceneComponent = CreateDefaultSubobject<UMySceneComponent>(TEXT("MySceneComponent"));
MySceneComponent->SetupAttachment(RootComponent);
アクターのブループリントでCapsuleの半径や高さを変えコンパイルするとデフォルト値に戻ってしまいます。
また、CapsuleComponentの詳細が表示されません(MySceneComponentの詳細は表示されています)
このCapsuleComponentのOnComponentBeginOverlapイベントにバインドさせたくてもできません。
コンポーネントのコンストラクタ内でのコンポーネント作成はどのように行うのが適切でしょうか?