C++ Adding a static mesh doesn't appear in editor

When adding a staticmesh to an actor, it doesn’t appear in editor.
If I edit the MeshComponent in the editor, its static mesh value is empty.

My code:

.h

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/StaticMeshComponent.h"
#include "MeleeTool.generated.h"

UCLASS()
class EREN_API AMeleeTool : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMeleeTool(const FObjectInitializer& ObjectInitializer);
protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category  = "Mesh")
		UStaticMesh* StaticMesh;
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Mesh")
		UStaticMeshComponent* MeshComponent;


	UFUNCTION()
		TMap<FName, int32> MeleeHit(const FVector StartTrace, FVector Dir);
};

.cpp

#include "MeleeTool.h"
#include "Classes/LandscapeStreamingProxy.h"
#include "Runtime/Engine/Classes/Components/StaticMeshComponent.h"
#include "EngineUtils.h"
#include "Classes/Landscape.h"
#include "EngineGlobals.h"
#include "Item/HarvestableObject.h"
#include "Net/UnrealNetwork.h"
#include "StaticMeshResources.h"
#include "Engine/StaticMesh.h"

// Sets default values
AMeleeTool::AMeleeTool(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;
	bReplicates = true;
	MeshComponent = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("MeleeToolMesh"));
	MeshComponent->SetStaticMesh(StaticMesh);
	RootComponent = MeshComponent;
}

What exactly do you mean by ‘empty’? In the editor, is the mesh component functional, but just doesn’t have the correct mesh assigned to it? Or is the mesh component itself completely blank, broken, and unusable?

By the way, is there any reason why you need a UStaticMesh and a UStaticMeshComponent? The UStaticMeshComponent class already provides its own UStaticMesh member that you can use to change the component’s visible mesh from within the editor. Your separate UStaticMesh member seems redundant to me, but I might not see the whole picture.

You don’t need UStaticMesh because UStaticMeshComponent has its own UStaticMesh, and it seems that in your case when you edit MeshComponent in the editor, this part

MeshComponent->SetStaticMesh(StaticMesh);

overrides it. Just try to remove it

The staticmesh property is set in editor. It doesnt appear in the UStaticMeshComponent static mesh value.