UCLASS()
class MIKETEST_API AMyTriggerBox : public AActor
{
GENERATED_BODY()
public:
AMyTriggerBox(const FObjectInitializer& ObjectInitializer);
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
private:
class UBoxComponent* _box;
UPROPERTY(EditDefaultsOnly)
class UStaticMeshComponent* MeshComp;
};
Cpp File
#include "MyTriggerBox.h"
#include "Components/BoxComponent.h"
#include "Engine.h"
AMyTriggerBox::AMyTriggerBox(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// 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;
_box = CreateDefaultSubobject<UBoxComponent>(TEXT("Box"));
_box->SetHiddenInGame(false);
_box->OnComponentBeginOverlap.AddDynamic(this, &AMyTriggerBox::OnBoxOverlapBegin);
_box->OnComponentEndOverlap.AddDynamic(this, &AMyTriggerBox::OnBoxOverlapEnd);
RootComponent = _box;
UStaticMeshComponent* MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TheMesh"));
}
So what have you tried. You’ve tried changing it to protected/public. Where are you trying to change the information. I’m going to load your code into my own project and see what’s going on.
I think you should re-read the answer I linked above. What are you trying to edit about the component? If you’d like to change the mesh, you do that in the TriggerBox as there is a property called Mesh Comp (See image)
I’m bit confused by some of your code and it could be what’s causing the issue. I notice that you declare your UProperty in your .h here:
UPROPERTY(EditDefaultsOnly)
class UStaticMeshComponent* MeshComp;
But when you go to use CreateDefaultSubobject to populate it, you aren’t setting it, you’re declaring yet another UStaticMeshComponent called MeshComp as well,
If you remove the “UStaticMeshComponent*” from the start of this line, it may fix your problems. The compiler is likely ignoring the original one that was declared in the .h and showing you this one, which is not a UProperty.
You still have the UPROPERTY set to Private and are also not using BlueprintReadWrite or a Category, which could help, depending on where you’re looking. With the screenshot you’re providing, I cannot tell which Details panel this is. Also, a Static Mesh Component would show up in the Components list, not in the same place as a normal Static Mesh or a Float value.
Can you show the constructor? If it is only containing RootComponent = MeshComp;, that’s also an issue as your UStaticMeshComponent needs to be initiated, using CreateDefaultSubobject, it just needs to be done correctly.
Using “class” allows for him to forward declare a class that has not been included in the .h file. This allows him to declare the property in his .h, and only include the necessary file in his .cpp.
However, I agree. This shouldn’t be needed for UStaticMeshComponent at least as it shouldn’t need to be forward declared unlike UBoxComponent would.
UPROPERTY(EditDefaultsOnly,Category “My Mesh”)
class UStaticMeshComponent* MeshComp;
Just for my education.
Why are you using “class” with an object declaration within the .h ?
Try without it and maybe the editor will catch your mesh.
UProperty is set to private even for the float variable and for the StaticMesh. So I don’t see the reason why it shouldn’t work for the MeshComponent.
Also, each of them has a category assigned.
As you can see there IS the MeshComponent on the left, but in an older project from Unreal Engine 4.13, I have the StaticMeshComponent behaving like the current StaticMesh: a box where I could choose the 3D Model to apply.
For the “it just needs to be done correctly”.
Well… there is a HUGE leak of documentation about using Unreal Engine with C++.
Yes, there are the basics… but many times it’s HARD to even find the documentation of an UE API class.
Not to talk about the Multiplayer… let’s just pretend I didn’t talk about it…
I just put this same setup together myself and I’m not even seeing the same issue you’re seeing. Are you sure you’re checking in the right spot? This is the setup I used and this is what I’m seeing when I click on the component in the blueprint:
Also, as I mentioned before, there have been many changes since 4.13 so the layout is different. If you look at the tags on that Playlist, it created even longer ago, in 4.10