Hello guys,
I´m currently struggling with a minor problem but it gets more and more annoying.
Suddenly the Details Panel looks “weird” after I created some Components by C++ Code.
I don´t even know exactly how to describe it but Pictures say more than 1000 Words so I attached some of what it looks like, how i wrote it in C++ and what I´m used to get.
The red marked Areas are the interesting parts.
This only occurs on Components that were created by Code, not for those which are added by Blueprint.
I noticed that they were not shown in the Components Tab on the left-lower side. Did I forgot to add them to some kind of components list?
Thank you very much!
mdeni
(mdeni)
May 25, 2016, 5:06pm
2
Looks like you forgot create those components in the constructor.
In header file something like this:
UCLASS()
class MEDIEVALTALES_API ALantern : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Components")
class UStaticMeshComponent* mesh;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Components")
class UPointLightComponent* light;
public:
// Sets default values for this actor's properties
ALantern();
}
And in *.cpp file something like this:
// Sets default values
ALantern::ALantern()
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.TickInterval = GameConstants::Intervals::Fps15;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
if (mesh)
{
// setup mesh here
mesh->AttachParent = RootComponent;
}
light = CreateDefaultSubobject<UPointLightComponent>(TEXT("Light"));
if (light)
{
// setup light here
light->AttachParent = RootComponent;
}
}
Oh, I totally forgot to send the .cpp also. That´s not it. I already created them in the constructor.
// Sets default values
AAB_Player::AAB_Player()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
DefaultSceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Default"));
PlayerCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("PlayerCamera"));
Controller_Left = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Controller_Left"));
Controller_Right = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("Controller_Right"));
Mesh_Left = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh_Left"));
Mesh_Right = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh_Right"));
RootComponent = DefaultSceneComponent;
PlayerCamera->AttachTo(RootComponent);
Controller_Left->AttachTo(RootComponent);
Mesh_Left->AttachTo(Controller_Left);
Controller_Right->AttachTo(RootComponent);
Mesh_Right->AttachTo(Controller_Right);
Controller_Left->Hand = EControllerHand::Left;
Controller_Right->Hand = EControllerHand::Right;
PlayerCamera->SetRelativeLocation(FVector(0.0f, 0.0f, 175.0f));
Controller_Left->SetRelativeLocation(FVector(0.0f, -40.0f, 100.0f));
Controller_Right->SetRelativeLocation(FVector(0.0f, 40.0f, 100.0f));
}
mdeni
(mdeni)
May 26, 2016, 6:20am
4
Perhaps you need to use those UPROPERTY parameters:
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = “Components”)
Other code looks right.
Okay, that fixxed it. I tested the different UPROPERTY Statements and the one that helped was “VisibleDefaultsOnly” instead of “EditAnywhere”. Now it looks like I wanted it to look.
Thank you very much!