Hey everybody,
I have a problem with a disappearing mesh:
I created a simple Actor:
MyActor.h
UCLASS()
class VRBASEFRAMEWORK_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent* ActorMesh;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UMySceneComponent* ChildScene;
};
MyActor.cpp
// Sets default values
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
ActorMesh= CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ActorMesh"));
RootComponent = ActorMesh;
ChildScene = CreateDefaultSubobject<UMySceneComponent>(TEXT("ChildScene"));
ChildScene->SetupAttachment(ActorMesh);
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
In the constructor i attached a custom scene component which also contains a mesh:
MySceneComponent.h
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class VRBASEFRAMEWORK_API UMySceneComponent : public USceneComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UMySceneComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent* ChildMesh;
};
MySceneComponent.cpp
// Sets default values for this component's properties
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;
ChildMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Child));
ChildMesh->SetupAttachment(this);
}
// Called when the game starts
void UMySceneComponent::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void UMySceneComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
Then i created a Blueprint which is based on the MyActor class.
In the Blueprint i set the StaticMesh for both the ActorMesh and ChildMesh.
When i compile the Blueprint now the ChildMesh disappears and i don’t know why that is.
Things i’ve noticed is that when I click on ChildMesh (Inherited) in the Components Panel the Details Panel is totally empty. When i click on ActorMesh (Inherited) I can see the Static Mesh Components variables.
Also the StaticMesh is still set in the Details Panel, but it doesn’t show up in the viewport.
Dragging the Actor into a map doesn’t work as well.
Another thing is that i can drag the ActorMesh into the EventGraph and get a Get or Set Node.
If i drag the ChildMesh into the Event Graph it gives the following error:
Cannot find correspondig variable (make sure component has been assigned to one).
I really hope that anyone can help me.
Cheers,
Adrian