Argument of type "UStaticMeshComponent " is incompatible with parameter of type "UStaticMesh "

Why I get this error ?

Blockquote

argument of type “UStaticMeshComponent *” is incompatible with parameter of type “UStaticMesh *”

#include "Components/StaticMeshComponent.h"
    static ConstructorHelpers::FObjectFinder<UStaticMeshComponent> CubeMesh(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere'"));
    
    	if (CubeMesh.Object) {
    		BombMesh->SetStaticMesh(CubeMesh.Object);
    	}

Hi,

Please try this:

    #include "Engine/StaticMesh.h"
    #include "UObject/ConstructorHelpers.h"

    static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeMesh(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere'"));

many thanks

did not work, thanks

if (CubeMesh.Succeeded()) {
BombMesh->SetStaticMesh(CubeMesh.Object);
}

compiler does not like setstaticmesh it say it is not comptatible with staticmeshcomponent !!

/** Put in header file */

private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Bomb", meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* BombMesh;

// Add to your Cpp
// Component Headers
#include "Components/StaticMeshComponent.h"

// Engine Headers
#include "Engine/StaticMesh.h"

// Constructor Helper
#include "UObject/ConstructorHelpers.h"


// Add to your constructor
 BombMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(" BombMesh"));

static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeMesh(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere'"));
if (CubeMesh.Succeeded()) {
          BombMesh->SetStaticMesh(CubeMesh.Object);
      }

I think you will need to accept the answer for it it be marked as resolved.