Don't Run Code In Tick Function

Instead of setting AllTriggerActorsTriggered in the Tick function it would be better to set that in the OnPressurePlateActivated() and OnPressurePlateDeactivated() function.

void UTransporter::OnPressurePlateActivated()
{
AllTriggerActorsTriggered = ++ActivatedTriggerCount >= TriggerActors.Num();
}

void UTransporter::OnPressurePlateDeactivated()
{
AllTriggerActorsTriggered = --ActivatedTriggerCount >= TriggerActors.Num();
}

This way the check to see if all the pressure plates are activated only occurs whenever a pressure plate has a character moving onto or off it rather than every tick.

2 Likes

I did pretty much the same but I prefer not to compound multiple effects on a single line, so I kept the ++ and – on a separate line.

I’m not really for or against. Having everything in one function makes it very simple to see what’s happening. Jumps complicate it and also are much worse for copy pasting and understanding later when you forget like having to look at headers or tracking things down in other classes.

As well as other points. I’m keeping this short so not stating every pro and con. But, small functions are good to a point and this is better named for understanding over having it in Tick anyway.

I’m of the keep the separate. The compiler will optimise the out anyway which is fine because, having started as a low level programmer, I know there are assembler operations for simple increment and decrement.

Plus readability and maintenance.

1 Like

Privacy & Terms