Can't edit Mesh in the Editor with UPROPERTY

Header File

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"));
}

The Editor

Already tried with EditAnywhere. Same problem.

I don’t want to make my MeshComp public, so I can’t use BlueprintReadWrite

try to make it “Protected” instead of “Private”

Already did that. No luck.

Hmm…maybe this answer can help you out?

I googled a lot before posting this issue. Didn’t find any working solution and posted here.

EVEN IF THE PROPERTY IS PUBLIC, the issue persists!

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.

EditAnywhere, EditDefaultsOnly… I’ve tried these combination too… nothing works

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)

Yes, I know that. But I can’t do anything if I click on TheMesh (Inherited)
I’d like to change those settings

This video shows what I want to achieve: C++ Battery Collector: Adding Variables & Functions | 04 | v4.9 Tutorial Series | Unreal Engine - YouTube

At 9:18, she can choose what should the Mesh be through the Blueprint-derived class in the Editor!

Hello ,

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,

UStaticMeshComponent* MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TheMesh"));

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.

Hello, thanks for the answer.

By the time, I deleted those lines and my constructor only contains

RootComponent = MeshComp;

For testing purposes, I added another UProperty of type UStaticMesh*

THAT appears!

But the UStaticMeshComponent does not!

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.

Thank you very much for you response.

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 already know the playlist you linked me: some replies above, I linked one video ( C++ Battery Collector: Adding Variables & Functions | 04 | v4.9 Tutorial Series | Unreal Engine - YouTube ) that shows how she creates a StaticMeshComponent and is able to assign a 3D Model to it

In MY case, I can only do that with a StaticMesh, and NOT a StaticMeshComponent

What’s the difference between the two?

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:

This is in 4.17. The constructor only has:

MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));

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