GameObject API: spawn, find, hierarchy, activation, name, destroy (#75) #82

Closed
opened 2026-09-06 01:24:54 +00:00 by crowmaki · 0 comments
Owner

Parent

#75

What to build

A Script reaches GameObjects with the names Unity uses. A GameObject reaching Luau is a userdata carrying the GameObject Handle, cached per Handle in a weak table so identity comparison works within a frame. Its metatable exposes name (read/write), parent (read/write), active (read/write) and activeInHierarchy (read-only) as properties, and IsAlive, SetActive, GetChildren (children in sibling order) and Destroy as methods. GameObject.new() and GameObject.new(name, parent) create a GameObject in the top Scene. GameObject.Find("scene:Room/Lamp") resolves a Display Path to a GameObject or nil. A global Destroy(go) matches go:Destroy(); both queue removal for the next Structural Flush. self.gameObject inside a Component method returns the owner.

Any access to a dead Handle raises a Luau error that names the operation; IsAlive is the one exception and never raises, answering false at once after destruction.

Acceptance criteria

  • GameObject.new() and GameObject.new(name, parent) create a GameObject visible to Odin via scene_object_count, gameobject_name and gameobject_parent
  • go.name reads and writes the Name; go.parent reads and writes the parent; go:GetChildren() lists children in sibling order
  • go.active, go:SetActive(false) and go.activeInHierarchy agree with gameobject_is_active and gameobject_is_active_in_hierarchy, including under an inactive ancestor
  • GameObject.Find resolves an authored Display Path and returns nil for an unknown one
  • Destroy(go) and go:Destroy() leave the GameObject alive until the next Structural Flush and gone after it
  • After destruction, go:IsAlive() is false and reading go.name raises an error whose message names the operation
  • Two lookups of the same GameObject in one frame compare equal with ==
  • self.gameObject in Awake returns the owner the Component was added to

Blocked by

## Parent #75 ## What to build A Script reaches GameObjects with the names Unity uses. A GameObject reaching Luau is a userdata carrying the GameObject Handle, cached per Handle in a weak table so identity comparison works within a frame. Its metatable exposes `name` (read/write), `parent` (read/write), `active` (read/write) and `activeInHierarchy` (read-only) as properties, and `IsAlive`, `SetActive`, `GetChildren` (children in sibling order) and `Destroy` as methods. `GameObject.new()` and `GameObject.new(name, parent)` create a GameObject in the top Scene. `GameObject.Find("scene:Room/Lamp")` resolves a Display Path to a GameObject or `nil`. A global `Destroy(go)` matches `go:Destroy()`; both queue removal for the next Structural Flush. `self.gameObject` inside a Component method returns the owner. Any access to a dead Handle raises a Luau error that names the operation; `IsAlive` is the one exception and never raises, answering false at once after destruction. ## Acceptance criteria - [ ] `GameObject.new()` and `GameObject.new(name, parent)` create a GameObject visible to Odin via `scene_object_count`, `gameobject_name` and `gameobject_parent` - [ ] `go.name` reads and writes the Name; `go.parent` reads and writes the parent; `go:GetChildren()` lists children in sibling order - [ ] `go.active`, `go:SetActive(false)` and `go.activeInHierarchy` agree with `gameobject_is_active` and `gameobject_is_active_in_hierarchy`, including under an inactive ancestor - [ ] `GameObject.Find` resolves an authored Display Path and returns `nil` for an unknown one - [ ] `Destroy(go)` and `go:Destroy()` leave the GameObject alive until the next Structural Flush and gone after it - [ ] After destruction, `go:IsAlive()` is false and reading `go.name` raises an error whose message names the operation - [ ] Two lookups of the same GameObject in one frame compare equal with `==` - [ ] `self.gameObject` in `Awake` returns the owner the Component was added to ## Blocked by - #80
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
crowmaki/cinnabar#82
No description provided.