How to delete or hide Chunks?

Everytime i’m trying to ‘release’ or ‘SetChunkVisible’ my project got crushed. What am i doing wrong?
Here is my(mostly Rama’s) code:

void AHappyDestructible::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

#if WITH_PHYSX
	
	for (FDestructibleChunkInfo& Each : GetDestructibleComponent()->ChunkInfos)
	{
		physx::PxRigidDynamic* Actor = Each.Actor;
		
		PxTransform Trans = Actor->getGlobalPose();
		PxVec3& PxLoc = Trans.p;
		
		FVector CLocation(PxLoc.x, PxLoc.y, PxLoc.z);
		FVector OffsetLoc = CLocation + FVector(30, 0, 0);
		
		PxVec3 PxTargetLoc = U2PVector(TargetALocation) - PxLoc;
		FVector PxTargetLocC = P2UVector(PxTargetLoc);
		float PxTargetLocSize = PxTargetLocC.Size();
		
		if (Actor)
		{
			Actor->addForce(PxTargetLoc, PxForceMode::eIMPULSE);
		}
		
		if (PxTargetLocSize < 500)
		{
			Actor->setLinearDamping(0);
			//Actor->release();
			//or
			//GetDestructibleComponent()->SetChunkVisible(Each.ChunkIndex,false);			
		}
		else
		{
			Actor->setLinearDamping(3);
		}
	}
#endif // WITH_PHYSX
}

Could you provide the crash log?

sry for the delay - heres is my crash log

The log states that you have a null access. Check the following line in your code:

UE4Editor-CodePhysTests.dll!AHappyDestructible::Tick() (0x000007fed835427a) + 16 bytes [d:\unreal projects\codephystests\source\codephystests\happydestructible.cpp:33]

I guess ‘physx::PxRigidDynamic* Actor = Each.Actor;’ is null though :slight_smile: