Sorry, we don't support your browser.  Install a modern browser

[scripting] Inconsistent errors when setting position and rotation vectors in Object.setSnapPoints#2298

When setting snap points on an object with Object.setSnapPoints(...), the position and rotation fields in snap points require, if provided with a table, that both x and y keys are set, if either x or y keys are set.

This behavior is outlandish.

All of these work (any x, y, or z not specified defaults to 0)

Object.setSnapPoints() -- No snap points
Object.setSnapPoints({}) -- same as above
Object.setSnapPoints({​{​}}) -- same as above

--The following actually result in a snap point being added to an objec
 -- Adds a snap point with all defaults (position, rotation all 0, no tags, rotation_snap false)
Object.setSnapPoints({ { {} }})
-- Add a snap point with position of {1, 0, 0} and other defaults
Object.setSnapPoints({ {position = {1} }}) 

Providing a table with indexed numerics for position or rotaiton works. Any field not specified defaults to 0 (which is sort of expected).

However, something extremely strange happens when we use string keys. Specifically, only one form works: if using string keys, both x and y must be specified, otherwise an error occurs. In other words:

Object.setSnapPoints({ {position = {x = 1, y = 1}}}) 

is the only form that works. Attempting to set position (or rotation) where any x=, y=, z= defined will not work unless both x and y are explicitly defined in the table. (z is optional. If not present defaults to 0). Anything else raises the error:

[12:34:15] Error converting Lua Table entry position to Type
UnityEngine. Vector 3 on Class LuaGameObjectScript+LuaSnapPointParameters. Value = MoonSharp.Interpreter.Table. (Error converting Table to Vector. (x, y, z or 1, 2, 3))

This issue is probably not specific to just Object.setSnapPoints, and likely effects many other methods where a parameter table contains a Vector, perhaps also those that expect a Color

7 days ago