Skip to main content

Maxlightspawner

Based on game build 714014 | Last updated: 2026-03-03

Overview

MaxLightSpawner manages a set of maxwelllight prefabs positioned in a circle around the owning entity. It handles spawning lights, tracking ownership, and persisting light references across save/load cycles. The component is designed for entities like Maxwell or Abigail that require decorative or functional lighting arrangements.

Usage example

local inst = CreateEntity()
inst:AddComponent("maxlightspawner")
inst.components.maxlightspawner.radius = 4
inst.components.maxlightspawner.maxlights = 3
inst.components.maxlightspawner:SpawnAllLights()

Dependencies & tags

Components used: None identified
Tags: Adds maxwelllight prefabs as children (via SpawnPrefab), but does not tag the spawner entity itself.

Properties

PropertyTypeDefault ValueDescription
lightstable{}Map of owned light entities (key and value both the light instance).
numlightsnumber0Current count of owned lights.
maxlightsnumber2Maximum number of lights this spawner may manage.
angleoffsetnumber0Initial angular offset (in degrees) for the light placement circle.
radiusnumber3Radius of the circle on which lights are spawned (in world units).
lightnamestring"maxwelllight"Name of the prefab to spawn for lights.

Main functions

TakeOwnership(light)

  • Description: Registers a light entity as owned by this spawner. Updates internal tracking.
  • Parameters: light (entity) — the light prefab instance to claim.
  • Returns: Nothing.

OnSave()

  • Description: Prepares light ownership data for saving. Collects GUIDs of all owned lights.
  • Parameters: None.
  • Returns: Two values:
    1. A data table containing { lights = {guid1, guid2, ...} }.
    2. The same lights array (redundant; likely legacy behavior).

OnLoad(data)

  • Description: Handles legacy save data format compatibility during load. Converts data.childid to data.lights if present.
  • Parameters: data (table) — raw save data passed from world loader.
  • Returns: Nothing.

LoadPostPass(newents, savedata)

  • Description: Restores light references after all entities are created. Reclaims ownership of lights using saved GUIDs.
  • Parameters:
    • newents (table) — mapping of GUIDs to entity instances created during world load.
    • savedata (table) — contains the lights array of GUIDs to reload.
  • Returns: Nothing.

SpawnLight(location)

  • Description: Spawns a single maxwelllight prefab at a given world position and registers it.
  • Parameters: location (Vector3) — world coordinates where the light should appear.
  • Returns: (entity or nil) — the newly spawned light, or nil if spawning failed.

SpawnAllLights()

  • Description: Spawns up to maxlights lights in a circular formation around the spawner entity's current position.
  • Parameters: None.
  • Returns: Nothing.
  • Error states: Does nothing if numlights >= maxlights.

Events & listeners

  • Listens to: None identified
  • Pushes: None identified