Strata - v1.4.10
    Preparing search index...

    Function useSystem

    • React hook for running an ECS system within React Three Fiber's render loop.

      Integrates ECS systems with R3F's useFrame hook. The system executes every frame with automatic cleanup on unmount. Supports dynamic enable/disable and priority control.

      Type Parameters

      Parameters

      • world: StrataWorld<T>

        The Strata ECS world to operate on.

      • system: SystemFn<T>

        The system function to execute each frame.

      • options: UseSystemOptions = {}

        Optional configuration (enabled, priority).

      Returns { isEnabled: () => boolean; setEnabled: (enabled: boolean) => void }

      Object with control methods to enable/disable the system.

      function Game() {
      const world = useMemo(() => createWorld<GameEntity>(), []);
      const [paused, setPaused] = useState(false);

      // System runs every frame
      useSystem(world, movementSystem, {
      enabled: !paused,
      priority: 0
      });

      useSystem(world, collisionSystem, {
      priority: 10 // Runs after movement
      });

      return <Canvas>...</Canvas>;
      }
      // Dynamic control
      function GameWithControl() {
      const world = useWorld();
      const { setEnabled, isEnabled } = useSystem(world, aiSystem);

      return (
      <button onClick={() => setEnabled(!isEnabled())}>
      Toggle AI: {isEnabled() ? 'ON' : 'OFF'}
      </button>
      );
      }