Update
The problem is the IsTemplate() function called from OnComponentCollisionSettingsChanged() in the static mesh component. Within IsTemplate, it checks the flags of the Outer object, however, the outer object is null. I’ve confirmed this is due to garbage collection by setting the garbage collection time to 1 second.
I have a Pawn with a UStaticMeshComponent and when the player presses a button, the collision and visibility states of this mesh are toggled. However, after 60 seconds the engine crashes on SetCollisionEnabled with an access violation (null pointer somewhere). The component is a UPROPERTY and the component pointer is valid since SetVisiblity works just fine and is called immediately before SetCollisionEnabled. I can also do MeshComponent->GetBodyInstance()->SetCollisionEnabled without a problem, so it must be something during the physics state checks.
60 seconds is when the garbage collector kicks in, so something is getting garbage collected when it shouldn’t be.
Am I missing something or is this a bug? Thanks!
Relevant code (using generic names):
State is a boolean indicating the toggle state.
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Mesh")
UStaticMeshComponent* MeshComponent;
MeshComponent->SetVisibility(State);
MeshComponent->SetCollisionEnabled(State? ECollisionEnabled::PhysicsOnly : ECollisionEnabled::NoCollision); // Works fine until 60 seconds have passed then it'll crash
I should also add that using SetCollisionEnabled on this particular mesh component causes this warning and I can’t find any information on why:
FBodyInstance::ApplyMaterialToShape_AssumesLocked : PComplexMats is empty - falling back on simple physical material.