Components
Components
Components are bits of functionality you can add to GameObjects. You can create a component to do anything you wish. There are also numerous components that exist in the s&box engine by default. You can find a list of example components within the sbox-scenestaging repo on Facepunch's GitHub.
Properties
An attribute [Property]
can be added to a property member on your component class, which allows you to slot in information about the property outside of code. This allows your component to be more re-usable.
See the Attributes and Component Properties page for more info and examples.
Methods
There are a number of methods you can override when making your own component. You can find a full list here. Below is an example of overriding a method.
Enabling and Disabling
You can enable or disable a component through code. When a component is disabled, methods like OnUpdate, OnFixedUpdate, and more are skipped. Whenever you enable a component, OnStart and OnEnabled will be called (in that order). Disabling a component calls OnDisabled.
Managing a Component on a GameObject
Most often, you will want to add components to a GameObject outside of the codebase (through the scene editor). But sometimes, there are cases you want to add to or remove from a GameObject directly.
From within a component, many properties of a GameObject (such as Transform, Components, Scene, etc) are exposed for you for convenience.