When I create my SceneComponent and attach it to an actor, I can see the arrow component and, when I move my SceneComponent, the arrow moves with it.
When I do the same thing for the static mesh component, I must set it in editor as if I did not CreateDefaultSubobject, and when I move the scene component, I see no motion for the static mesh.
Debugging in VS shows that the EyeMesh is non null after creation. When inspecting the children of my SceneComponent, I can see that EyeMesh is an attached child.
Header
#pragma once
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "Components/ArrowComponent.h"
...
#include "Components/StaticMeshComponent.h"
#include "SC_2DEye.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class SB_CELSHADING_API USC_2DEye : public USceneComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
USC_2DEye();
UPROPERTY()
UArrowComponent* m_eyeArrow;
UPROPERTY(EditAnywhere)
UStaticMeshComponent* EyeMesh;
...
}
CPP
USC_2DEye::USC_2DEye()
{
if (IsTemplate())
{
return;
}
PrimaryComponentTick.bCanEverTick = true;
m_eyeArrow = CreateDefaultSubobject<UArrowComponent>(TEXT("EyeDirection3D"));
m_eyeArrow->SetupAttachment(this);
EyeMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("EyeMesh"));
EyeMesh->SetMobility(EComponentMobility::Movable);
EyeMesh->SetupAttachment(this);
}