Instanced static mesh component - PerInstanceRenderData.IsValid() assertion fail when cooking

Hi everyone

In my project I have an Actor programmed in C++ which spawns floor panels as UInstancedStaticMeshComponent. When this actor is placed in a map the project failes to cook. With the following error message. There is an other thread with the exact same error message but the cause is different.

[SPOILER]


UATHelper: Cooking (Windows):   LogWindows: Error: begin: stack for UAT
UATHelper: Cooking (Windows):   LogWindows: Error: === Critical error: ===
UATHelper: Cooking (Windows):   LogWindows: Error:
UATHelper: Cooking (Windows):   LogWindows: Error: Assertion failed: PerInstanceRenderData.IsValid() [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp] [Line: 1951]
UATHelper: Cooking (Windows):   LogWindows: Error:
UATHelper: Cooking (Windows):   LogWindows: Error:
UATHelper: Cooking (Windows):   LogWindows: Error:
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff90f7fa839 KERNELBASE.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8ac90a9e6 UE4Editor-Core.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8ac90de88 UE4Editor-Core.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8ac6c2cbd UE4Editor-Core.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8ac64fd83 UE4Editor-Core.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8ac652100 UE4Editor-Core.dll!UnknownFunction ]
PackagingResults: Error: begin: stack for UAT
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8a9852710 UE4Editor-Engine.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8a9852299 UE4Editor-Engine.dll!UnknownFunction ]
PackagingResults: Error: === Critical error: ===
PackagingResults: Error: Assertion failed: PerInstanceRenderData.IsValid() [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp] [Line: 1951]
PackagingResults: Error: [Callstack] 0x00007ff90f7fa839 KERNELBASE.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8ac0b14a9 UE4Editor-CoreUObject.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8ac90a9e6 UE4Editor-Core.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8ac90de88 UE4Editor-Core.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8ac6c2cbd UE4Editor-Core.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8ac64fd83 UE4Editor-Core.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8ac652100 UE4Editor-Core.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8a9852710 UE4Editor-Engine.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8a9852299 UE4Editor-Engine.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8ac0b14a9 UE4Editor-CoreUObject.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8ac0d33f8 UE4Editor-CoreUObject.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff8ac0d33f8 UE4Editor-CoreUObject.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff8ac0b9baa UE4Editor-CoreUObject.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff88f9a4175 UE4Editor-UnrealEd.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff88f84d952 UE4Editor-UnrealEd.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff88f84fd0c UE4Editor-UnrealEd.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff88f85acd9 UE4Editor-UnrealEd.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff88f6f2778 UE4Editor-UnrealEd.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff88f71801f UE4Editor-UnrealEd.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff670682fb0 UE4Editor-Cmd.exe!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff67067c17c UE4Editor-Cmd.exe!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff67067c4ca UE4Editor-Cmd.exe!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff67068ceae UE4Editor-Cmd.exe!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff67068ede2 UE4Editor-Cmd.exe!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff9117f7bd4 KERNEL32.DLL!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error: [Callstack] 0x00007ff91274ced1 ntdll.dll!UnknownFunction ]
UATHelper: Cooking (Windows):   LogWindows: Error:
UATHelper: Cooking (Windows):   LogWindows: Error: end: stack for UAT
PackagingResults: Error: [Callstack] 0x00007ff8ac0b9baa UE4Editor-CoreUObject.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff88f9a4175 UE4Editor-UnrealEd.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff88f84d952 UE4Editor-UnrealEd.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff88f84fd0c UE4Editor-UnrealEd.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff88f85acd9 UE4Editor-UnrealEd.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff88f6f2778 UE4Editor-UnrealEd.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff88f71801f UE4Editor-UnrealEd.dll!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff670682fb0 UE4Editor-Cmd.exe!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff67067c17c UE4Editor-Cmd.exe!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff67067c4ca UE4Editor-Cmd.exe!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff67068ceae UE4Editor-Cmd.exe!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff67068ede2 UE4Editor-Cmd.exe!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff9117f7bd4 KERNEL32.DLL!UnknownFunction ]
PackagingResults: Error: [Callstack] 0x00007ff91274ced1 ntdll.dll!UnknownFunction ]
PackagingResults: Error: end: stack for UAT

[/SPOILER]

As you can see the error is related to an Instanced static mesh component that is for some reason not valid when the project is cooked. In the editor the project runs perfectly fine.

This is some mock up code of what I think is a non working minimal example (please ignore the deprecated AttachTo etc.)



//CPP

//Constructor
AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer){
    PrimaryActorTick.bCanEverTick = true;
    //Set RootComponent and get Meshes, generate UInstancedStaticMeshcomponent and set it up
    RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
    static ConstructorHelpers::FObjectFinder<UStaticMesh> FloorAsset(TEXT("StaticMesh'/Game/Models/FloorTile/Floortile.Floortile'"));
    //Floor is pointer to a UInstancedStaticMeshComponent declared in the header
    Floor = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("Floor"));
    Floor->AddWorldTransform(GetTransform());
    Floor->SetStaticMesh(FloorAsset.Object);
    Floor->SetCollisionProfileName(TEXT("BlockAll"));
    Floor->AttachTo(RootComponent);
}

//This is the other part where the instanced mesh is used. In the OnConstruction routine I spawn a floor with a desired size X and Y
void ASectionActorC::OnConstruction(const FTransform & Transform)
{
    Super::OnConstruction(Transform);
    for (int i = 0; i < TotalSizeX(); ++i) {
        for (int j = 0; j < TotalSizeY(); ++j) {
            //Create an Instance at some predefined point FindLocalCoordinate returns a 3Vector
            FTransform ObjectTransform{ FindLocalCoordinate(i, j) };
            ObjectTransform.NormalizeRotation();
            Floor->AddInstance(ObjectTransform);
        } 
    }    
}


What am I doing wrong here? Thank you very much for your help

Update:
I could narrow down the cause of this issue. It only happens if I place more than one of these actors inside the level. Is this a bug?

Update 2:
The issue only happens if the actor is used as a Child Actor inside another actor. I think i can work around this.

Hi, do you fix the issue? I met the same problem

I had similar issue in same source but cooking log didnt give exact information whats wrong.
If you have engine source, you can add a logger to the line where you get crash in instancedstaticmesh.cpp, rebuild and run the cooking again:


                if(!PerInstanceRenderData.IsValid())
                {
                    UE_LOG(LogStaticMesh, Warning, TEXT("InstanceRenderData invalid for %s (%s) in %s."), *GetName(), *GetOwner()->GetName(), *Ar.GetArchiveName());
                }

                check(PerInstanceRenderData.IsValid());

for me, it showed my problem is a foliage instanced mesh item.

Thanks for this tipp in the engine! This saved me hours of work finding the causing Mesh.

For me it was also two foliage actors which did not survive the migration from UE4.22 to UE4.23