Problem with changing the location of the PlatformTrigger

I was trying to implement a little recoil on the pressure pad.
When I tried using the scheme GetActorLocation -> Change -> SetActorLocation inside the PlatformTrigger.cpp the UE4Editor crashed. There’s another way I could do this?

I wanted to do a similar thing thing. This was my solution to make the button depress and reset when someone was standing on it or not. It caused a crash initially for me as well before I accounted for multiple actors standing on it at once. Seemed like it doesn’t like being set to a negative value compared to root, but I’m not sure what exactly was the issue.

UPROPERTY(EditAnywhere) float DepressAmount = 5;
int32 OverlappingActors = 0;
void APlatformTrigger::OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	if (OverlappingActors++ == 0)
	{
		Mesh->AddRelativeLocation(FVector(0, 0, -DepressAmount));
	}

	for (AMovingPlatform* Platform : Platforms)
	{
		if (Platform)
		{
			Platform->AddActiveTrigger();
		}
	}
}
void APlatformTrigger::OnOverlapEnd(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex)
{
	if (--OverlappingActors == 0)
	{
		Mesh->AddRelativeLocation(FVector(0, 0, DepressAmount));
	}
	
	for (AMovingPlatform* Platform : Platforms)
	{
		if (Platform)
		{
			Platform->RemoveActiveTrigger();
		}
	}
}

Privacy & Terms