Unclaimed Project Is this your project? Claim it to unlock full analytics and manage your listing.
Claim This Project

Unity Project

Download the source from GitHub

Game Core Time Channels

Dependencies (43)

README

Time Channels for Unity

Unity Version License: MIT

A lightweight and highly controllable time channel system for Unity β€” designed to replace Unity's global Time.timeScale with modular, per-system control.

Why Not Use Time.timeScale?

Unity's built-in Time.timeScale affects the entire game globally, which limits your ability to create nuanced time effects. For example, you can't easily:

  • Pause UI while gameplay continues
  • Slow down enemies without affecting player controls
  • Run multiple independent timelines in parallel

Time Channels solves these problems by allowing each gameplay system to operate on its own independently scaled timeline.

✨ Features

  • Per-System Time Scaling: Assign unique time scales to players, enemies, weather, UI, and more
  • Modular Architecture: Clean separation of channel creation, management, and usage
  • String-Based Channel Naming: Easily register and retrieve custom time channels by name
  • Pause/Resume Per Channel: Control specific systems without impacting the entire game
  • Event System: React to time scale changes with OnTimeScaleChanged callbacks
  • Flexible Signal System: Use TimeChannelSignal for complex, dynamic time effects

πŸ“¦ Installation

Via Git URL

  1. Open Window > Package Manager
  2. Click the + button and select "Add package from git URL"
  3. Enter: https://github.com/BcoffeeDev/game-core-time-channels.git?path=/Packages/com.bcoffee-dev.time-channels
  4. Click Add

Requirements

  • Unity 2019.4 or newer
  • No additional dependencies

πŸš€ Quick Start

1. Register a time channel

TimeChannelManager.Register("Player", SupportedTime.DeltaTime);

2. Access time in your Update loop

float dt = TimeChannelManager.Get("Player").DeltaTime;
transform.Translate(Vector3.forward * speed * dt);

3. Adjust time scale at runtime

TimeChannelManager.Get("Player").TimeScale = 0.5f; // Slow motion effect

πŸ“– Usage Examples

Create a custom time channel without the manager

var customChannel = TimeChannelFactory.Create(SupportedTime.FixedDeltaTime);
customChannel.TimeScale = 0.8f;
float dt = customChannel.DeltaTime;

Pause and resume a specific channel

var enemy = TimeChannelManager.Register("Enemy", SupportedTime.DeltaTime);

// Pause: set scale to 0 (remember previous scale if you need to restore it)
float prevScale = enemy.TimeScale;
enemy.TimeScale = 0f;

// Resume: restore previous scale
enemy.TimeScale = prevScale;

Note: TimeChannel has no built-in Pause()/Resume() methods. Pausing is done by setting TimeScale to 0f, and resuming by restoring a non-zero scale.

Use TimeChannelSignal for advanced effects

public class MovingCube : MonoBehaviour
{
    [SerializeField] private TimeChannelSignal signal;
    
    void Update()
    {
        if (signal.Channel != null)
        {
            float dt = signal.Channel.DeltaTime;
            // Use dt for movement, animation, etc.
        }
    }
}

React to time scale changes

var channel = TimeChannelManager.Get("Player");
channel.OnTimeScaleChanged += (newScale) => {
    Debug.Log($"Player time scale changed to: {newScale}");
    // Update UI, play effects, etc.
};

πŸ“š API Overview

Component Description
TimeChannelManager Register, retrieve, and manage named time channels
TimeChannel Core time channel with DeltaTime, TimeScale, and events
TimeChannelFactory Create custom time channels independent of the manager
TimeChannelSignal MonoBehaviour component for advanced time control
SupportedTime Enum defining Unity's built-in time types

Core Methods

// TimeChannelManager
TimeChannel Register(string name, SupportedTime type, float defaultTimeScale = 1f)
TimeChannel Get(string name)
bool Has(string name)
void Unregister(string name)
void Clear()

// TimeChannel  
float DeltaTime { get; }
float TimeScale { get; set; }
SupportedTime Type { get; }
event Action<float> OnTimeScaleChanged

πŸ§ͺ Samples

The package includes two comprehensive samples:

  • BasicExample: Demonstrates fundamental usage of time channels
  • TimeControlExample: Shows TimeChannelSignal with trigger-based time effects

To import samples:

  1. Open Window > Package Manager
  2. Select Time Channels
  3. Click the Samples tab
  4. Import the desired sample

πŸŽ₯ Demo

Basic Example Basic time channel control with pause/resume functionality

Time Control Example
Advanced time effects using TimeChannelSignal

⚠️ Best Practices

  • Avoid mixing with global Time.timeScale - Don't use Unity's global Time.timeScale alongside this system
  • Register channels early - Register all channels in Awake() or Start()
  • Use descriptive names - Choose meaningful channel names like "Player", "Enemies", "Weather"
  • Clean up properly - Call TimeChannelManager.Unregister() when channels are no longer needed
  • Handle null references - Always check if channels exist before using them

πŸ”„ Changelog

[1.1.0] - 2025-08-02

  • Added OnTimeScaleChanged event to TimeChannel
  • Added TimeChannelSignal for flexible time control
  • Modified TimeChannelManager.Register to return existing channels
  • Renamed timeScale parameter to defaultTimeScale

[1.0.0] - 2025-07-06

  • Initial release
  • Core time channel system
  • Manager and factory classes
  • Basic sample scenes

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

  1. Fork this repository
  2. Clone your fork: git clone https://github.com/your-username/game-core-time-channels.git
  3. Create a feature branch: git checkout -b feature/amazing-feature
  4. Make your changes and commit: git commit -m 'Add amazing feature'
  5. Push to the branch: git push origin feature/amazing-feature
  6. Open a Pull Request

πŸ“„ License

MIT License Β© 2025 Bcoffee

See LICENSE for more details.

πŸ› Issues & Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed information
  3. Include Unity version, error messages, and reproduction steps

⭐ If this project helps you, please consider giving it a star!

Comments

No comments yet. Be the first!