# Time Manipuulation

**URL:** <https://discussions.unity.com/t/time-manipuulation/1715749>\
**Category:** Navigation\
**Tags:** Navigation, Physics, Conversation, 6.4\
**Created:** [April 7, 2026, 8:51pm UTC](https://discussions.unity.com/t/time-manipuulation/1715749 "2026-04-07T20:51:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RG-Poly](https://avatars.discourse-cdn.com/v4/letter/r/ee59a6/32.png) [@RG-Poly](https://discussions.unity.com/u/RG-Poly)\
**Post date:** [April 7, 2026, 8:51pm UTC](https://discussions.unity.com/t/time-manipuulation/1715749/1 "2026-04-07T20:51:13Z")

</div>

Hey everyone,

A few weaks ago, I shared post about how my simple “time-rewind prototype” spiraled out of control when I realized that rewinding time in Unity isn’t just about recording positions—it’s a massive coordination problem across physics, NavMesh, particles, and foreign scripts.  
. So, I wanted to share some of the architecture of what I now call the _Time Paradox Engine_.

Here are the 4 biggest hurdles and how I solved them.

### 1. The Memory Nightmare (Solving it with Zero-GC & Bitwise Masking)

If you record `Transform` data for 100 objects at 60 FPS for 10 seconds, and use standard `List<T>` or classes, the Garbage Collector will eventually cause massive lag spikes.

To fix this, I used **NativeArrays** and a pure `struct` for snapshots. To make the circular buffer lightning-fast, I forced its size to be a power of two. This allows us to use bitwise masking instead of the slow `%` modulo operator for wrapping around the buffer.

```csharp
// Inside TimeWarpBuffer.cs
// AAA OPTIMIZATION: Power of 2 sizing for bitwise masking
int rawCount = Mathf.CeilToInt(framerate * maxTime);
Count = Mathf.NextPowerOfTwo(rawCount); 
_mask = Count - 1; // Used for ultra-fast wrapping

public int GetIndex(int offset)
{
    // Completely eliminates while loops and modulo operations. O(1) retrieval.
    return (Head - 1 - offset) & _mask;
}

```

To actually apply these thousands of recorded positions during a rewind, I offloaded the work to the **Burst Compiler and Job System** using `IJobParallelForTransform` with unmanaged pointers (`TransformSnapshot**`). The main thread barely notices the rewind is happening.

### 2. Frozen Physics & The “Stasis” Problem

What happens when you shoot an enemy while time is stopped? Unity’s default behavior is to do nothing, because to freeze a `Rigidbody`, you usually set `isKinematic = true`.

I built a `KineticAccumulator` to catch these forces. If time is stopped, the object absorbs the force into a `Queue<Vector3>`. When time resumes, a Coroutine releases the stored hits sequentially, creating an awesome delayed-impact effect.

```csharp
// Inside KineticAccumulator.cs
public void AddKineticImpact(Vector3 forceVector)
{
    if (TimeWarpManager.Instance.GlobalTimeState == TimeState.Normal) {
        _rb.AddForce(forceVector, ForceMode.Impulse);
        return;
    }
    // Accumulate energy during the freeze!
    _accumulatedForce += forceVector;
    _impactQueue.Enqueue(forceVector);
}

private IEnumerator ReleaseSequentialRoutine()
{
    while (_impactQueue.Count > 0)
    {
        if (_rb.isKinematic) yield break; // Time stopped again? Pause the queue!
        
        Vector3 hit = _impactQueue.Dequeue();
        _rb.AddForce(Vector3.ClampMagnitude(hit, MaxForceCap), ForceMode.Impulse);

        yield return new WaitForSeconds(SequentialDelay);
    }
}

```

### 3. Creating “Time Ghosts” without melting the CPU

Rewinding is cool, but what if you want to leave a clone (Echo) that replays your past actions?

The hardest part is replaying _events_ (like shooting a gun) without triggering massive memory allocations. I created a `TimeEventPayload`—a lightweight struct that acts as a data pocket.

```csharp
// Inside TimeEventPayload.cs
[System.Serializable]
public struct TimeEventPayload
{
    public int EventHash; // e.g., Animator.StringToHash("Shoot")
    public float Float1;
    public int Int1; // Ammo index, weapon ID, etc.
    public Vector3 Vector1; // Aim direction
}

```

When the player shoots, they pass this struct into the `TimeEventRecorder`. When the Ghost spawns, it interpolates through the recorded history. If it hits a frame with a recorded EventHash, a `GhostEventReceiver` catches it and calls the exact same `PerformShoot(Vector3 dir, float force, int ammo)` method the player uses.

It’s completely decoupled and relies on string hashes, meaning you can plug it into _any_ existing weapon script without rewriting your game logic.

### 4. The Kill-Switch for Foreign Scripts

The final realization: **No time system can magically fix a badly written character controller.**  
If your Turret script is constantly looking at the player in `Update()`, it will fight the Rewind system.

Instead of modifying every script in the game, I built a `TimeWarpComponentManager`. It acts as an automated kill-switch. When an anomaly starts, it automatically disables non-time-aware `Behaviour` components.

```csharp
// Inside TimeWarpComponentManager.cs
bool shouldBeDisabled = isRewinding && DisableOnRewind || isTimeStopped && DisableOnTimeStop;

if (shouldBeDisabled && !_componentsAreDisabledByUs)
{
    for (int i = 0; i < TargetComponents.Count; i++)
        TargetComponents[i].enabled = false;
        
    _componentsAreDisabledByUs = true;
}
// When time resumes, it re-enables them and fires OnTimeWarpResume() 
// via an ITimeWarpStateListener interface so they can reset their internal timers.

```

### Final Thoughts

Building a robust time system forces you to treat Unity differently. You stop relying on `Time.deltaTime` and start thinking in ticks, custom scaling, and decoupled data buffers.

If you’re interested in checking out the full system, I’m packaging it into an asset called the **Time Paradox Engine**.  
👉 [[Link to Demo Showcase](https://play.unity.com/en/games/8d96e8fc-1cd5-4892-a2bd-058ce5fb19bc/time-paradox-engine)]

Have any of you used rewinding mechanics? What was the hardest thing to sync in your experience? (For me, it was definitely matching Cinemachine camera cuts with frame rewinds to prevent motion sickness!). Let me know your thoughts!

---

<div class="post-metadata">

**Author:** ![CodeSmile](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/codesmile/32/82968_2.png) [@CodeSmile](https://discussions.unity.com/u/CodeSmile)\
**Post date:** [April 8, 2026, 6:30pm UTC](https://discussions.unity.com/t/time-manipuulation/1715749/2 "2026-04-08T18:30:45Z")

</div>

> [@RG-Poly](#):
>
> A few weaks ago, I shared post about how my simple “time-rewind prototype” spiraled out of control when I realized that rewinding time in Unity isn’t just about recording positions—it’s a massive coordination problem across physics, NavMesh, particles, and foreign scripts.

Yes! And it starts with “pause” … really not as simple as `timeScale = 0`. 😉

[Chronos](https://github.com/CyberSys/ChronosTimeControl) used to be a popular asset on the store for time manipulation.

PS: When you rewind time, don’t forget about sending the input back to the device, since that’s “future input” now… 🤓

> [@RG-Poly](#):
>
> The final realization: **No time system can magically fix a badly written character controller.**

… and 98% of them are badly written.
