Savedscale
Overview
This component ensures that an entity's transform scale is saved to and restored from the game save file. It records non-default scale components (i.e., values not equal to 1) in a compact format during OnSave and applies them during OnLoad, defaulting missing axes to the x-scale for symmetry.
Dependencies & Tags
- Requires the
Transformcomponent to be present on the same entity (viaself.inst.Transform). - No component dependencies added (
AddComponent). - No tags are added or removed.
Properties
No public properties are initialized in the constructor or elsewhere. The component relies solely on the inst reference passed at construction.
Main Functions
OnSave()
- Description: Captures the entity’s current transform scale (x, y, z) and returns a compact table containing only non-default (non-1) scale components. Specifically:
xis saved only if ≠ 1.yis saved only if ≠x.zis saved only if ≠x. Returnsnilif all scales are 1 (no custom scaling).
- Parameters: None.
OnLoad(data)
- Description: Restores the entity’s transform scale from saved
data. Usesdata.xas the base scale, defaulting to 1. Then sets:- x =
data.xor 1 - y =
data.yor (x value) - z =
data.zor (x value)
- x =
- Parameters:
data(table or nil): Optional saved scale data. Ifnilor empty, scales are reset to (1,1,1).
Events & Listeners
None.