error: cannot initialize a parameter of type 'UObject *' with an lvalue of type 'UStaticMesh *'

Hello 0/
I have some problem with compil for html5 (compil for win not problem)
I have standart code for staticmesh



auto CubeVisualAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));

But it’s not working for html5, pls hep me

Error logs


In file included from C:\Users\proff\Documents\Unreal Projects\HoN_testing\Source\HoN_testing\Planet.cpp:6:
LogPlayLevel: Error: Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(110,20): error: cannot initialize a parameter of type 'UObject *' with an lvalue of type 'UStaticMesh *'
LogPlayLevel: ValidateObject( Object, PathName, ObjectToFind );
LogPlayLevel: ^~~~~~
LogPlayLevel: C:\Users\proff\Documents\Unreal Projects\HoN_testing\Source\HoN_testing\Planet.cpp(21,25): note: in instantiation of member function 'ConstructorHelpers::FObjectFinder<UStaticMesh>::FObjectFinder' requested here
LogPlayLevel: auto CubeVisualAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));
LogPlayLevel: ^
LogPlayLevel: Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(206,38): note: passing argument to parameter 'Object' here
LogPlayLevel: static void ValidateObject(UObject *Object, const FString& PathName, const TCHAR* ObjectToFind)
LogPlayLevel: ^
LogPlayLevel: Error: Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(34,19): error: incomplete type 'UStaticMesh' named in nested name specifier
LogPlayLevel: UClass* Class = T::StaticClass();
LogPlayLevel: ^~~
LogPlayLevel: Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(109,41): note: in instantiation of function template specialization 'ConstructorHelpersInternal::FindOrLoadObject<UStaticMesh>' requested here
LogPlayLevel: Object = ConstructorHelpersInternal::FindOrLoadObject<T>(PathName);
LogPlayLevel: ^
LogPlayLevel: C:\Users\proff\Documents\Unreal Projects\HoN_testing\Source\HoN_testing\Planet.cpp(21,25): note: in instantiation of member function 'ConstructorHelpers::FObjectFinder<UStaticMesh>::FObjectFinder' requested here
LogPlayLevel: auto CubeVisualAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));
LogPlayLevel: ^
LogPlayLevel: Runtime\Engine\Classes\Engine/EngineTypes.h(2617,8): note: forward declaration of 'UStaticMesh'
LogPlayLevel: class UStaticMesh* DistanceFieldReplacementMesh;
LogPlayLevel: ^
LogPlayLevel: In file included from C:\Users\proff\Documents\Unreal Projects\HoN_testing\Source\HoN_testing\Planet.cpp:6:
LogPlayLevel: Error: Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(39,13): error: member access into incomplete type 'UStaticMesh'
LogPlayLevel: ObjectPtr->AddToRoot();
LogPlayLevel: ^
LogPlayLevel: Runtime\Engine\Classes\Engine/EngineTypes.h(2617,8): note: forward declaration of 'UStaticMesh'
LogPlayLevel: class UStaticMesh* DistanceFieldReplacementMesh;
LogPlayLevel: ^
LogPlayLevel: In file included from C:\Users\proff\Documents\Unreal Projects\HoN_testing\Source\HoN_testing\Planet.cpp:4:
LogPlayLevel: In file included from C:\Users\proff\Documents\Unreal Projects\HoN_testing\Source\HoN_testing/Planet.h:6:
LogPlayLevel: In file included from Runtime\Engine\Classes\GameFramework/Actor.h:8:
LogPlayLevel: In file included from Runtime\CoreUObject\Public\UObject/UObjectBaseUtility.h:12:
LogPlayLevel: In file included from Runtime\CoreUObject\Public\UObject/UObjectBase.h:12:
LogPlayLevel: Error: Runtime\CoreUObject\Public\UObject/UObjectGlobals.h(1369,31): error: incomplete type 'UStaticMesh' named in nested name specifier
LogPlayLevel: return (T*)StaticLoadObject( T::StaticClass(), Outer, Name, Filename, LoadFlags, Sandbox );
LogPlayLevel: ^~~
LogPlayLevel: Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(36,18): note: in instantiation of function template specialization 'LoadObject<UStaticMesh>' requested here
LogPlayLevel: T* ObjectPtr = LoadObject<T>(NULL, *PathName);
LogPlayLevel: ^
LogPlayLevel: Runtime\CoreUObject\Public\UObject/ConstructorHelpers.h(109,41): note: in instantiation of function template specialization 'ConstructorHelpersInternal::FindOrLoadObject<UStaticMesh>' requested here
LogPlayLevel: Object = ConstructorHelpersInternal::FindOrLoadObject<T>(PathName);
LogPlayLevel: ^
LogPlayLevel: C:\Users\proff\Documents\Unreal Projects\HoN_testing\Source\HoN_testing\Planet.cpp(21,25): note: in instantiation of member function 'ConstructorHelpers::FObjectFinder<UStaticMesh>::FObjectFinder' requested here
LogPlayLevel: auto CubeVisualAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));
LogPlayLevel: ^
LogPlayLevel: Runtime\Engine\Classes\Engine/EngineTypes.h(2617,8): note: forward declaration of 'UStaticMesh'
LogPlayLevel: class UStaticMesh* DistanceFieldReplacementMesh;
LogPlayLevel: ^
LogPlayLevel: 4 errors generated.
LogPlayLevel: Error: shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting
LogPlayLevel: Took 14,1682293s to run UnrealBuildTool.exe, ExitCode=5
LogPlayLevel: UnrealBuildTool failed. See log for more details. (C:\Users\proff\AppData\Roaming\Unreal Engine\AutomationTool\Logs\D+UE4+UE_4.23\UBT-HoN_testing-HTML5-Development.txt)
LogPlayLevel: AutomationTool exiting with ExitCode=5 (5)
LogPlayLevel: Completed Launch On Stage: Build Task, Time: 13.775454
LogPlayLevel: BUILD FAILED
PackagingResults: Error: Launch failed! Unknown Error

.cpp


// Fill out your copyright notice in the Description page of Project Settings.


#include "Planet.h"
#include "Components/StaticMeshComponent.h"
#include "UObject/ConstructorHelpers.h"

#include "UObject/SoftObjectPtr.h"
#include "UObject/SoftObjectPtr.h"
#include "UObject/UObjectGlobals.h"

// Sets default values
APlanet::APlanet()
{
// 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;

VisualMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
VisualMesh->SetupAttachment(RootComponent);

auto CubeVisualAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));

if (CubeVisualAsset.Succeeded())
{
   VisualMesh->SetStaticMesh(CubeVisualAsset.Object);
   VisualMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
}

}

// Called when the game starts or when spawned
void APlanet::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void APlanet::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

FVector NewLocation = GetActorLocation();
FRotator NewRotation = GetActorRotation();
float RunningTime = GetGameTimeSinceCreation();
float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
NewLocation.Z += DeltaHeight * 20.0f; //Scale our height by a factor of 20
float DeltaRotation = DeltaTime * 20.0f; //Rotate by 20 degrees per second
NewRotation.Yaw += DeltaRotation;
SetActorLocationAndRotation(NewLocation, NewRotation);

}



.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Planet.generated.h"

UCLASS()
class HON_TESTING_API APlanet : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor's properties
APlanet();

UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* VisualMesh;

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

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

};


Hey man,

It is really hard to read it, but try to change from static mesh to static mesh component:

auto CubeVisualAsset = ConstructorHelpers::FObjectFinder<UStaticMeshComponent>(TEXT(“StaticMesh’/Engine/BasicShapes/Sphere.Sphere’”));

You need to include the header for static mesh and static mesh component. It’s complaining because it doesn’t know what it is.

Don’t do the above - a StaticMesh is not the same thing as a StaticMeshComponent.

Yes, thx, it’s working