Create a Component – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
(Page creation)
 
m (Fix)
Line 91: Line 91:
</enforce>
</enforce>


Now all there is to do is to place one {{hl|TAG_Component}} entity in the world and see its effects!
Now all there is to do is to attach a {{hl|TAG_Component}} component to a world entity and see its effects!





Revision as of 12:22, 5 May 2024

A World Editor Component is a code element that can be placed as a child (well, as a component) of an entity from the World Editor's Add Component button.

In this example, we will create a Component that does something.

🏗
This article is a work in progress! Reason: Code in progress


Declaration

Component

Create a new file and name it as your component - here, we will go with TAG_Component so the file should be TAG_Component.c.

By convention, all Component classnames must end with the Component suffix.
A component script file must be created in the Game module (scripts/Game), otherwise it will not be listed in the Components list!

class TAG_Component : GameComponent // GameComponent > GenericComponent { }

Component Class

Like an Entity, a Component requires a Component Class declaration. This allows it to be visible in World Editor. The name must be exactly the Component name suffixed by Class, here TAG_ComponentClass. A Component Class is usually placed just above the Component definition as such:

[ComponentEditorProps(category: "Tutorial/Component", description: "TODO")] class TAG_ComponentClass : GameComponentClass { } class TAG_Component : GameComponent { }

The class is decorated using ComponentEditorProps; the category is where the Component will be found using e.g the Add Component button - see below.

ComponentEditorProps

category
the "Create" tab's category in which the Component can be found
description
unused (for now)
color
the bounding box's unselected line colour - useful only when visible is set to true
visible
have the bounding box always visible - drawn in color
insertable
configRoot
unused
icon
unused: direct path to a png file, e.g WBData/EntityEditorProps/entityEditor.png
In order for the component to appear in World Editor, scripts must be compiled and reloaded via ⇧ Shift + F7.


Filling

The Component is now visible in World Editor's "Add Component" UI, the next step is to make it do something.

Add Code

Let's use the Component's OnPostInit() method to call code.

// TODO


Add Properties

Now, we can declare properties with the Attribute in order to be able to adjust some settings from the World Editor interface. The following code only contains the added attributes:

// TODO

The following code contains code with the implemented attributes:

// TODO

Now all there is to do is to attach a TAG_Component component to a world entity and see its effects!


Final Code

The final file content can be found here:

// TODO