I recently started to learn about the unreal engine and I’m currently starting with the basics, it turns out that I tried to load an asset from the example content provided by the engine itself and I’ve tried everything, but the asset apparently doesn’t load at all.
The code is very simple. I create an instance with the FObjectFinder and then check if the object was successfully loaded, if so it shows a message saying that everything is ok, otherwise a failure message is shown, but it always falls on the failure message and that’s it I do not know what else to try.
void AMesher::BeginPlay()
{
Super::BeginPlay();
static ConstructorHelpers::FObjectFinder<UStaticMesh> CylinderAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cylinder.Shape_Cylinder"));
if (CylinderAsset.Succeeded())
{
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Green, TEXT("Got it"));
} else {
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("Fail"));
}
}```
Thank you for any help.
You should only use ConstructorHelpers in the constructor. If you move that to your constructor ( AMesher::AMesher() ) it should work - or use another way to load packages:
Thank you for your reply, in fact after I take a better look into the unreal framework source code there is a function that checks if it is called inside the constructor, this information is such interesting, but the fact is that I already tried to use the code in constructor and I had no success.
After a lot of more time expended looking into source code and unreal docs I learned how to copy asset reference trough unreal ui interface and noticed the wrong file path and that was the issue I was having.\
Mesher::Mesher()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you dont need it.
PrimaryActorTick.bCanEverTick = true;
static ConstructorHelpers::FObjectFinder<UStaticMesh> meuMesh(TEXT("/Engine/BasicShapes/Sphere.Sphere"));
if(meuMesh.Succeeded())
{
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Green, TEXT("Asset loading works!"));
umesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyPrettyCube"));
bool loaded = umesh->SetStaticMesh(meuMesh.Object);
if(loaded)
{
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Green, TEXT("Success in Asset assign!"));
} else {
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("Asset assign has failed!"));
}
} else {
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("Fail in mesh loading!"));
}
}
Now I’ll take more a look at the other example code that you provided, Thank you for your contribution.