Hello, Every one.
Recently I have a problem, It occurs when BP Actor inherited from My C++ Actor.
I wirte a App Actor, like this:
// .h file
UCLASS()
class COSMOS_API MyCppActor: public AActor
{
GENERATED_BODY()
static FName BackName;
public:
UPROPERTY(Category = TestCG, VisibleAnywhere, BlueprintReadWrite)
USceneComponent* Root;
UPROPERTY(Category = TestCG, VisibleAnywhere, BlueprintReadWrite)
class UStaticMeshComponent* Back;
public:
MyCppActor();
virtual void BeginPlay() override;
virtual void Tick( float DeltaSeconds ) override;
};
// .cpp file
FName MyCppActor::BackName(TEXT("BackMesh"));
MyCppActor::MyCppActor()
{
PrimaryActorTick.bCanEverTick = true;
Root = CreateDefaultSubobject<USceneComponent>(TEXT("MyRoot"));
UStaticMesh* TmpMesh = nullptr;
UMaterialInterface* TmpMat = nullptr;
UMaterialInstanceDynamic* tmpMID = nullptr;
if (Root)
{
Back = CreateDefaultSubobject<UStaticMeshComponent>(MyCppActor::BackName);
Back->bCastDynamicShadow = false;
// load mesh from plugin Meshes dir and set to Back(an UStaticMeshComponent*)
TmpMesh = DSUtility::LoadMeshFromPath(TEXT("/MyTestPlugin/Meshes/Back"));
Back->SetStaticMesh(TmpMesh);
// load material from plugin Materials dir
TmpMat = DSUtility::LoadMatFromPath(TEXT("/MyTestPlugin/Materials/Back"));
// create material instance and set to mesh
tmpMID = Back->CreateAndSetMaterialInstanceDynamicFromMaterial(0, TmpMat);
Back->AttachParent = Root;
}
RootComponent = Root;
}
void MyCppActor::BeginPlay()
{
Super::BeginPlay();
}
void MyCppActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
In Editor, when I created an Cpp MyActor instance into scene, there is no problem, all right.
But, if I create a new BP Actor(MyBpActor) inherit from CPP Actor(MyCppActor) and create instance from BP Actor(MyBpActor), There will be problems.
I can’t see any material instance on Back(UStaticMeshComponent).
May I ask why? and How to solve this problem?
thank you.