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);
}
GEODVS
(GEODVS)
2
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'"));
GEODVS
(GEODVS)
5
if (CubeMesh.Succeeded()) {
BombMesh->SetStaticMesh(CubeMesh.Object);
}
compiler does not like setstaticmesh it say it is not comptatible with staticmeshcomponent !!
GEODVS
(GEODVS)
7
/** 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);
}
GEODVS
(GEODVS)
8
I think you will need to accept the answer for it it be marked as resolved.