Packaging a game make instance static meshes not render

Hello,

I’m having an issue when packaging my project.
On one of the levels, I’m using instanced static meshes. When I launch the game in the editor every load fine I can see the meshes and the materials

However, when I package the game and load into the level none of the actors is rendered.



FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::DontSpawnIfColliding;
SpawnedMStarRef = GetWorld()->SpawnActor<AMStar>(MStarActor->StaticClass(), FVector(0, 0, 0), FRotator(0, 0, 0), SpawnParameters


for (auto ZPos = initZ; ZPos <= endZ; ZPos += 10) {
    instanceId = SpawnedMStarRef->Star->AddInstanceWorldSpace(FTransform(rotation, starCoordinates, FVector(size)));
}


I’m wondering its there a config setting I’m missing to enable to project to be packaged?

Other levels that are not using instance static meshes work fine, so my assumption is its something to do with this it strange that it loads fine in the editor but not when packaged.

Both are loading in the same location and are saying the same amount of actor where found
Editor:

](filedata/fetch?id=1835951&d=1606297263)

Packaged:

](filedata/fetch?id=1835952&d=1606297293)

Thanks for any help in advance.

So I think they are being rendered on the screen, just the materials are not loading when packaging.

This is how I’m loading the materials.



UMaterial* AAStar::LoadMaterialFromPath(const FName& Path)
{
if (Path == NAME_None) return nullptr;

return LoadObjFromPath<UMaterial>(Path);
}

template <typename ObjClass>
ObjClass* AAStar::LoadObjFromPath(const FName& Path)
{
if (Path == NAME_None) return nullptr;

return Cast<ObjClass>(StaticLoadObject(ObjClass::StaticClass(), nullptr, *Path.ToString()));
}

void AAStar::BeginPlay()
{
Star->SetMaterial(0, LoadMaterialFromPath("/Game/Levels/Galaxy/AMaterial"));
Super::BeginPlay();

}


Ok figured it out just don’t do what I was doing when loading materials.
I will leave my constructor code if anyone else stumbles on this. This loads up the materials correctly.



AMStar::AMStar()
{
// 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;
Star = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("Star"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> StarAsset(TEXT("/Game/Levels/Galaxy/GalaxyStarSphere"));

static ConstructorHelpers::FObjectFinder<UMaterial> MaterialAsset(TEXT("Material'/Game/Levels/Galaxy/MMaterial'"));

if (MaterialAsset.Succeeded())
{
Material = MaterialAsset.Object;

if (StarAsset.Succeeded())
{
Star->SetMaterial(0, Material);
Star->SetStaticMesh(StarAsset.Object);
Star->SetRelativeLocation(FVector(0.0f));
Star->Mobility = EComponentMobility::Static;
Star->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
Star->SetCollisionObjectType(ECollisionChannel::ECC_WorldDynamic);
Star->BodyInstance.SetCollisionProfileName("StarCollision");
Star->CastShadow = false;
}
}

RootComponent = Star;
}