Skip to main content

Ugc Swap Fx

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

Overview

ugc_swap_fx defines reusable prefab factories for dynamic visual effects that replace surface symbols (e.g., pumpkin carvings or snowman decorations) on owner entities. It uses MakeUgcSwapFx to generate prefabs (pumpkincarving_swap_fx, snowmandecorating_swap_fx) that mirror customizations applied by the player. The component synchronizes data (customization profile) and flag (optional state) via networked strings/booleans, then updates visuals in real time using AnimState:SetAddColour and symbol rendering callbacks. It interacts with colouraddersync for additive colour control and relies on PumpkinCarvable and SnowmanDecoratable to generate geometry.

Usage example

-- Example: Create a pumpkin carving effect attached to a player
local fx = SpawnPrefab("pumpkincarving_swap_fx")
fx.entity:SetParent(player.entity)
fx:SetData({
{ type = "cut", frame = 2, angle = 0.5 },
{ type = "cut", frame = 5, angle = 1.2 }
}, false)

Dependencies & tags

Components used: colouraddersync, transform, network Tags: Adds CLASSIFIED to each instance. External dependencies: components/pumpkincarvable, components/snowmandecoratable

Properties

PropertyTypeDefault ValueDescription
piecestable{}Array of visual entities (meshes/symbols) generated by carver/decorator.
datanet_stringNetworked string storing customisation data (e.g., carve paths).
flagnet_boolfalseOptional networked boolean for state flags (e.g., toggle mode).
_applyfnfunctionCallback (per FX type) that regenerates visual pieces from data.
followsymbolstring""Symbol name to attach effects on owner (e.g., "swap_body", "swap_item").

Main functions

SetData(inst, data, flag)

  • Description: Sets the customisation data and optional flag on the server, triggering a full visual refresh on all clients.
  • Parameters: data (any) — serialisable customization profile; flag (boolean?) — optional state flag.
  • Returns: Nothing.
  • Error states: Only valid on master simulation (TheWorld.ismastersim).

MakeUgcSwapFx(name, applyfn, common_postinit, master_postinit)

  • Description: Factory function returning a Prefab that creates a networked swap FX entity with configurable behavior for server/client logic.
  • Parameters:
    • name (string) — prefab name.
    • applyfn (function) — applies visuals using data/flag.
    • common_postinit (function?) — initialization run on both server and client.
    • master_postinit (function?) — initialization run only on master.
  • Returns: Prefab — a prefabricated entity factory.
  • Error states: None beyond normal prefab construction.

Events & listeners

  • Listens to: datadirty — triggers _ondatadirtyfn to refresh visuals and recompute owner context.
  • Pushes: None directly; relies on component events (colouraddersync triggers OnColourDirty internally).