You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The GameObject class represents an entity in the scene graph. It can have components, children, and a transform for position, rotation, and scale. GameObjects are the core building blocks for all objects in the engine, similar to Unity's GameObject.
The Transform component for position, rotation, scale
id
int
Unique identifier for this GameObject
Location
String
Hierarchical path of this GameObject
layer
int
Layer bitmask for rendering and filtering
components
List
List of attached components
Methods
/** * Constructs a GameObject with a given name and initializes its Transform. * @param name The name of the GameObject */publicGameObject(Stringname)
/** * Adds a child GameObject by parenting its Transform to this GameObject's Transform. * @param child The child GameObject to add */publicvoidaddChild(GameObjectchild)
/** * Adds a component to this GameObject. * @param component The component instance to attach */publicvoidaddComponent(Componentcomponent)
/** * Retrieves the first component of the specified type attached to this GameObject. * @param <T> The class type of the component * @param type The class object representing the desired component type * @return The component instance if found; otherwise, null */public <TextendsComponent> TgetComponent(Class<T> type)
/** * Called at a fixed interval (using Time.fixedDeltaTime). * Typically used for physics or time-consistent logic. */publicvoidfixedUpdate()
/** * Called once every frame. Updates all components and recursively updates all children. */publicvoidupdate()
/** * Called once every frame after update(). Responsible for rendering this GameObject and its children. * @param camera The camera to render with * @param layerMask The layer mask for rendering */publicvoidrender(Cameracamera, intlayerMask)
/** * Called after render(), only in debug mode or when needed. Used to draw debug visuals like bounding boxes, axis lines, etc. */publicvoiddebugRender()
/** * Recursively updates the Location string for this GameObject and all children. */publicvoidUpdateLocation()
/** * Returns the hierarchical path of the GameObject in the scene tree. * @param gb The GameObject * @return The path string */publicstaticStringLocation(GameObjectgb)
/** * Finds a GameObject by its path, recursively searching the hierarchy. * @param path The path string * @param root The root GameObject to search from * @return The found GameObject, or null if not found */publicstaticGameObjectfindGameObject(Stringpath, GameObjectroot)
/** * Finds a GameObject by its path using an iterative approach. * @param path The path string * @param root The root GameObject to search from * @return The found GameObject, or null if not found */publicstaticGameObjectfindGameObjectItrative(Stringpath, GameObjectroot)
/** * Recursively prints the hierarchy of GameObjects starting from this one. */publicvoidprintHierarchy()
/** * Reparents this GameObject to a new parent GameObject, preserving world transform. * @param newParent The GameObject to become the new parent */publicvoidreparentTo(GameObjectnewParent)
/** * Gets the layer bitmask. * @return The layer bitmask */publicintgetLayerBit()
/** * Sets the layer bitmask. * @param newLayer The new layer bitmask */publicvoidsetLayer(intnewLayer)
/** * Sets the layer for this object only. * @param newLayer The new layer bitmask */publicvoidsetLayerOnly(intnewLayer)
/** * Sets the layer for this object and all its children recursively. * @param layerBit The new layer bitmask */publicvoidsetLayerRecursively(intlayerBit)
/** * Sets the layer from layer(bit) name (for convenience). * @param layerName The name of the layer * @param recursive Whether to set recursively */publicvoidsetLayerByName(StringlayerName, booleanrecursive)
/** * Returns a readable string representation of the GameObject. * @return String representation */@OverridepublicStringtoString()
/** * Returns all the components of a GameObject. * @return List of components */publicList<Component> getAllComponents()
/** * Removes a component from this GameObject. * @param cmp The component to remove */publicvoidremoveComponent(Componentcmp)
/** * Destroys a GameObject and all its children, removing them from the hierarchy and clearing components. * @param thisGb The GameObject to destroy */publicstaticvoiddestroy(GameObjectthisGb)
/** * Gets/Sets the unique ID, name, transform, layer, and components. */publicintgetId(); publicvoidsetId(intid);
publicStringgetName(); publicvoidsetName(Stringname);
publicTransformgetTransform(); publicvoidsetTransform(Transformtransform);
publicintgetLayer(); publicvoidsetLayer(intlayer);
publicList<Component> getComponents(); publicvoidsetComponents(List<Component> components);
publicintgetComponentCount();
Example Usage
GameObjectplayer = newGameObject("Player");
player.addComponent(newPlayerController());
GameObjectenemy = newGameObject("Enemy");
player.addChild(enemy);
player.update(); // Calls update on player and all children// Find a GameObject by pathGameObjectfound = GameObject.findGameObject("/Player/Enemy", root);
// Set layer recursivelyplayer.setLayerRecursively(2);
Best Practices
Use addComponent to attach logic/behavior to GameObjects
Use addChild to build hierarchies (e.g., player with weapon as child)
Use findGameObject for path-based lookups
Use setLayerRecursively for group rendering/filtering