Im tryng to make a BP class into a C++ class, so I’m making the BP class inherit from the new C++ class.
But when I bring a BP into the world I can’t see or edit its StaticMeshComponent declared in the parent c++ class.
Also I initialize the component in the constructor and gets initialized, but when the begin play executes, the component is referencing NULL.
However when I bring into the world an instace of the parent C++ class I can see and edit it and works as expected.
C++ .h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Engine/DataTable.h"
#include "Ingredient.generated.h"
USTRUCT()
struct BLANC_API FIngredientMeshes : public FTableRowBase
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMesh* Ingredient;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMesh* Spawner;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMesh* Middle;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMesh* Mixed;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FName Heat;
};
UCLASS()
class BLANC_API AIngredient : public AActor
{
GENERATED_BODY()
public:
AIngredient(const FObjectInitializer& ObjectInit);
protected:
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FName BaseType = TEXT("Tomato");
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FName> IngredientList;
UPROPERTY(BlueprintReadOnly)
UDataTable* DataTable;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
USceneComponent* SceneComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
UStaticMeshComponent* StaticMesh;
};
C++ .cpp
#include "Ingredient.h"
AIngredient::AIngredient(const FObjectInitializer& ObjectInit)
: Super(ObjectInit)
{
PrimaryActorTick.bCanEverTick = false;
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
RootComponent = SceneComponent;
StaticMesh->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UDataTable> DT_Ingredients(TEXT("DataTable'/Game/VRCooked/Data/DT_Ingredient.DT_Ingredient'"));
if (DT_Ingredients.Succeeded())
{
DataTable = DT_Ingredients.Object;
}
FIngredientMeshes* Ingredientt = DataTable->FindRow<FIngredientMeshes>(BaseType, "");
StaticMesh->SetStaticMesh(Ingredientt->Ingredient);
BaseType = TEXT("Lettuce");
}
void AIngredient::BeginPlay()
{
Super::BeginPlay();
if (StaticMesh == NULL) {
UE_LOG(LogTemp, Error, TEXT("IS NULL"));
}
else{
UE_LOG(LogTemp, Error, TEXT("NOT NULL"));
};
UE_LOG(LogTemp, Error, TEXT("%s"), *BaseType.ToString());
}
BP