Instanced Static Mesh component error after third instance

Hello,

When I add more than two instances to an instanced static mesh component I get the following error:

Assertion failed: FromInst->OwnerComponent.Get() == NULL [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.5\Engine\Source\Runtime\Engine\Private\PhysicsEngine\BodyInstance.cpp] [Line: 2524]

Note that I ran the exact same code under 4.4 and there was no problem. I even set up a clean project. Still there is the problem. So far I have found out that the line which causes the crash did not change between 4.4 and 4.5. Therefore there must have been a change about OwnerComponent.

I somehow got this working again I will report back when I find out why

is my code:

//TestBAse.m just a regular actor
#include "InstancedTest.h"
#include "TestBAse.h"
#include "MyStaticMeshActor.h"


ATestBAse::ATestBAse(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

}

void ATestBAse::BeginPlay()
{
	FActorSpawnParameters SpawnInfo;

	//SET NO COLLISION FAIL TO TRUE
	SpawnInfo.bNoCollisionFail = true;

	SpawnInfo.Owner = nullptr;

	AMyStaticMeshActor* NewVertex =
		GetWorld()->SpawnActor<AMyStaticMeshActor>(
		AMyStaticMeshActor::StaticClass(),
		FVector(0,0,0),
		FRotator::ZeroRotator,
		SpawnInfo
		);
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	//Mesh
	//NewVertex->InstancedStaticMeshComponent->SetStaticMesh(VictoryEngine->AssetSM_EngineCube);

	//Add Core Instance
	for (int32 x = 0; x < 80; x++)
	{
		for (int32 y = 0; y < 80; y++)
		{
			FVector2D jea = FVector2D(x, y);
			FTransform newT = NewVertex->GetTransform();
			newT.SetLocation(FVector(x*200, y*200, 0));
			NewVertex->InstancedStaticMeshComponent->AddInstance(newT);
		}
	}
	

	//Scale
	NewVertex->SetActorRelativeScale3D(FVector(1,1,1));
}


//MyStaticMeshActor.cpp Just copied over from ramas post
#include "InstancedTest.h"
#include "MyStaticMeshActor.h"


AMyStaticMeshActor::AMyStaticMeshActor(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	//Mesh
	static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshOb_torus(TEXT("StaticMesh'/Engine/EngineMeshes/Cube.Cube'"));
	SMAsset_Cube = StaticMeshOb_torus.Object;

	//create new object
	InstancedStaticMeshComponent = PCIP.CreateDefaultSubobject < UInstancedStaticMeshComponent >(this, TEXT("InstancedStaticMeshComponentCOMP"));
	InstancedStaticMeshComponent->AttachTo(RootComponent);

	//Not Made some reason?
	if (!InstancedStaticMeshComponent) return;
	//~~~~~~~~~~~~~~~~~~~~~~~~

	//Set to Asset
	InstancedStaticMeshComponent->SetStaticMesh(SMAsset_Cube);

	InstancedStaticMeshComponent->bOwnerNoSee = false;
	InstancedStaticMeshComponent->bCastDynamicShadow = false;
	InstancedStaticMeshComponent->CastShadow = false;
	InstancedStaticMeshComponent->BodyInstance.SetObjectType(ECC_WorldDynamic);
    //If i make this below, it crashes after one instance with the same error although when checking it is not null 
    InstancedStaticMeshComponent->BodyInstance.OwnerComponent = Cast<UPrimitiveComponent>(InstancedStaticMeshComponent);

	//Visibility
	InstancedStaticMeshComponent->SetHiddenInGame(false);

	//Mobility
	InstancedStaticMeshComponent->SetMobility(EComponentMobility::Movable);

	//Collision
	InstancedStaticMeshComponent->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryOnly);
	InstancedStaticMeshComponent->BodyInstance.SetObjectType(ECC_WorldDynamic);
	InstancedStaticMeshComponent->BodyInstance.SetResponseToAllChannels(ECR_Ignore);
	InstancedStaticMeshComponent->BodyInstance.SetResponseToChannel(ECC_WorldStatic, ECR_Block);
	InstancedStaticMeshComponent->BodyInstance.SetResponseToChannel(ECC_WorldDynamic, ECR_Block);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


	if (!StaticMeshComponent) return;

	//Mobility
	StaticMeshComponent->SetMobility(EComponentMobility::Movable);

	//Collision
	StaticMeshComponent->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryOnly);
	StaticMeshComponent->BodyInstance.SetObjectType(ECC_WorldDynamic);
	StaticMeshComponent->BodyInstance.SetResponseToAllChannels(ECR_Ignore);
	StaticMeshComponent->BodyInstance.SetResponseToChannel(ECC_WorldStatic, ECR_Block);
	StaticMeshComponent->BodyInstance.SetResponseToChannel(ECC_WorldDynamic, ECR_Block);
}

Note that both .h have nothing in them except the pregenerated stuff.

I am pretty confident that this is a bug as other people experience it as well

This does not happen when using blueprints, so I am going to investigate that

Greetings,

Bump, really stuck

Nobody got any answers?

Bumpedibump.

I echo this problem. It did not effect my build in 4.4, but crashes now in 4.6 immediately after adding a third instance to a static mesh. My code is very similar to the above. Does anyone know the answer to this?

Hey DJ_Lectr0

Please do report back when you figure out how to get this working. My project is relatively stuck (at 1FPS) until I can get instanced static mesh components again.

Also, just a heads-up, it’s way easier to keep track of what’s going on in the thread if you add new comments when you have something new to say as opposed to editing the original post. Thanks!

I am having this problem, though in my case, I am in blueprint.

While in the editor, it works great (I use Add Instance Static Mesh Component followed by calls to AddInstance in the Constructor Script), but as soon as I press play, I received the “FromInst->OwnerComponent.Get() == NULL” assertion error.

I’m running 4.6.1, and changing the AddInstancedStaticMeshComponent with AddStaticMeshComponent does not have any problems.

Note: I realize this is a c++ post, but I thought it might be related.

This is still a major problem for me.

If anyone is using instanced static mesh component successfully in C++, could you please post your relevant code for comparison?

I have this issue as well i have one class with the instance component works perfectly no problems. And in a derived class of the same class (Same Code).
It crashes on the 3rd instance added.

Very very od.

Anyone had any luck solving this issue?

Is the code that’s working for you (in one class) functionally similar to what’s in the original post?

Did some more testing and now both class are running same code no difrence.
Only difrence now is the static mesh and that the one that works is the root component on the class/ BP.

Edit:

Is the code that’s working for you (in
one class) functionally similar to
what’s in the original post?
All collision stuff is setup in the constructor.
When adding i only use AddInstanceToWorldSpace()

And the ones that crashes are attach to that parent every thing else is the same.
Also i get this crash if i try exiting PiE with one or two of them in the scene.

Assertion failed:
!HasValidPhysicsState()
[File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.6\Engine\Source\Runtime\Engine\Private\ActorComponent.cpp]
[Line: 833] Failed to destroy physics
state (InstancedStaticMeshComponent
/Game/UEDPIE_0

Happens to me as well after adding 3rd instance. 4.6.1, through c++ too.

I also concur this. Crash in UInstancedStaticMeshComponent::CreateAllInstanceBodies → UInstancedStaticMeshComponent::InitInstanceBody → FBodyInstance::CopyBodyInstancePropertiesFrom assert on check(FromInst->OwnerComponent.Get() == NULL);

Happens when adding 3rd instance. Doing through c++. What’s really bizarre is that it does not happen for each static mesh, only for some.

This is obviously a pretty big issue judging by the amount of responses; can we please get some Epic feedback?

So apparantely when I take out this line of code:

InstancedStaticMeshComponent->AttachTo(RootComponent);

It stops crashing after the third instance. Please comment on this answer if this solves it for you.

I have had success with the same code in 4.7 preview 3 (I haven’t tried the other previews). I sorely look forward to 4.7’s release!

I found this thread while searching for the assert failure, and but am experiencing it with a strictly blueprint set up (prototyping in BP, blah blah).

Thanks to 's comment above, I was able to realize that only the instanced mesh set as the ROOT component would work to an arbitrary number of instances; unchecking AutoWeld on the StaticMesh properties allowed me to use any of the components.

Again, I’m not doing any of this in the code right now, but it fixed the issue in BP. Whether this fix creates further issues is to be seen!

This is great news i am strugeling to find the AutoWeld setting you are talking about.
Could you please direct me the proper location.
Checkt both settings in the Static Mesh Editor and Instanced STatic Mesh Components on my actor.

Am i just blind or is it some where else?

Edit:
I did find InstancedStaticMeshComponent->UnWeldFromParent(); this it?

Thanks.

The Auto Weld option is in the Blueprint window, Components view, in the Physics category for each of the components. My Blueprint’s parent class is Actor.h, and has a Root component of Instanced Static Mesh, and three additional components of Instanced Static Mesh.

I’m not sure about in code; a quick find all on the source shows bAutoWeld is a uprop in the FBodyInstance class; StaticMeshComponent’s constructor uses GetBodyInstance()->bAutoWeld = true; to turn on static mesh welding by default.

Well that solved my crashes it seems :smiley:
is a snip of my contructor if anyone wants to know.

InstanceOne = PCIP.CreateDefaultSubobject(this, "Instance One");
if (InstanceOne)
{
    RootComponent = InstanceOne;
    InstanceOne->GetBodyInstance()->bAutoWeld = false;
}
    	 
InstanceTwo = PCIP.CreateDefaultSubobject(this, "Instance Two");
if (InstanceTwo)
{
    InstanceTwo->AttachParent = InstanceOne;
    InstanceTwo->GetBodyInstance()->bAutoWeld = false;
}

Hey if you want to keep it attached to the Root Component of your actor.
Then

RootComponent = InstancedStaticMeshComponent;
InstancedStaticMeshComponent->GetBodyInstance()->bAutoWeld = false;

Solved the issue for me and not had any more crashes.

For longer snip see below.