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