This is a procedure to solve the troublesome behavior where events are called twice due to hardware load (processing failure) when using Timeline and C# cooperation (signals) by controlling the receiving code side.
Specific solution
Debouncing implementation in C# receiver code (Signal Receiver)
In the method that directly receives events from Timeline, write a check gate that automatically ignores multiple firings at a short time as shown below.
private float lastFiredTime = -1f;
private const float DebounceThreshold = 0.1f; // Regards as a duplicate within 100ms
public void OnReceiveSignal()
{
if (Time.time - lastFiredTime < DebounceThreshold)
{
return; // Detects double fire and discards
}
lastFiredTime = Time.time;
// ...Actual event processing...
}
*By simply inserting this simple defense code, no matter how many stutters (FPS drops) occur in the actual machine environment, you can completely prevent the fatal behavior of in-game events being executed twice.
Figure 1: Flow of signal duplication processing and debounce solution due to processing drop (frame skip)