Skip to content

StrangeHub

Fynn9563 edited this page Jan 28, 2026 · 1 revision

StrangeHub

Video Tutorial

Coming soon - video tutorial placeholder

The StrangeHub is the central manager component for Strange Toolkit. It handles atmosphere switching, toggle persistence, and object tracking.

Overview

Every world using Strange Toolkit needs exactly one StrangeHub. It's created automatically via the World Tab or can be added manually.

Properties

Atmosphere System

Property Type Description
atmosphereNames string[] Display names for each atmosphere
atmosphereDefaults bool[] Which atmosphere loads on world start
atmosphereSkyboxes Material[] Skybox material for each atmosphere
atmosphereUseFog bool[] Whether fog is enabled per atmosphere
atmosphereFogColors Color[] Fog color per atmosphere
atmosphereFogDensities float[] Fog density per atmosphere
atmosphereRoots GameObject[] Root objects to toggle per atmosphere

Cleanup System

Property Type Description
cleanupProps GameObject[] Objects to track for position reset

Public Methods

Atmosphere Control

ApplyAtmosphere(int index)

Switches to the specified atmosphere.

// Switch to atmosphere at index 2
hub.ApplyAtmosphere(2);

What it does:

  1. Sets the skybox material
  2. Enables/disables fog
  3. Sets fog color and density
  4. Toggles linked root objects (previous off, new on)

NextAtmosphere()

Cycles to the next atmosphere in the list.

// Cycle to next atmosphere
hub.NextAtmosphere();

Wraps around to the first atmosphere after the last.

Toggle Persistence

SaveToggleState(string id, bool state)

Saves a toggle state for the current player.

// Save that "bedroom_light" is ON
hub.SaveToggleState("bedroom_light", true);

LoadToggleState(string id, bool defaultState)

Retrieves a saved toggle state, or returns the default if not found.

// Load state, default to false if not saved
bool isOn = hub.LoadToggleState("bedroom_light", false);

How Persistence Works

The hub maintains parallel arrays for persistence:

  • _savedIds[] - Toggle identifiers
  • _savedStates[] - Corresponding boolean states

When a toggle saves state:

  1. Hub searches for existing ID
  2. If found, updates the state
  3. If not found, adds new entry (arrays expand in chunks of 32)

Note: Persistence is per-player, stored locally. It resets when the player leaves and rejoins.

Lifecycle

On World Load

  1. Hub initializes persistence arrays
  2. Finds the default atmosphere (first with atmosphereDefaults[i] == true)
  3. Applies the default atmosphere

During Gameplay

  • Toggles call SaveToggleState() on interaction
  • Atmosphere switches call NextAtmosphere() or ApplyAtmosphere()

On Player Rejoin

  • Toggles call LoadToggleState() to restore their state

Editor Integration

The hub works with custom inspectors:

  • StrangeHubEditor - Shows atmosphere management UI
  • World Tab - Creates and configures the hub

Best Practices

Placement

  • Keep at scene root level
  • Don't parent to moving objects
  • Ensure it's always active

Atmosphere Setup

  • Set exactly one default atmosphere
  • Use linked roots for complex lighting changes
  • Keep skybox materials optimized

Persistence IDs

  • Use unique, descriptive IDs
  • Keep IDs consistent across versions
  • Document your ID scheme

Example: Manual Atmosphere Setup

// In another UdonSharp behavior
public StrangeHub hub;

public void SwitchToNightMode()
{
    // Assuming night is at index 1
    hub.ApplyAtmosphere(1);
}

public void CycleAtmosphere()
{
    hub.NextAtmosphere();
}

Troubleshooting

Atmosphere not changing

  • Check that arrays are properly sized (all same length)
  • Verify skybox materials are assigned
  • Check for null references in linked roots

Persistence not working

  • Verify toggles have unique IDs
  • Check that toggles reference the hub
  • Ensure usePersistence is enabled on toggles

Fog not applying

  • Check atmosphereUseFog is true for that index
  • Verify fog is enabled in lighting settings
  • Check fog density isn't zero

Clone this wiki locally