WorldEditorAPI Usage – Arma Reforger
Lou Montana (talk | contribs) (Add Native Type Array section) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
Line 9: | Line 9: | ||
Game classes such as {{hl|WorldEditorAPI}}, {{hl|ScriptEditor}} etc must '''not''' be a strong {{hl|ref}} script-side; on scripts reload, these references are not nulled and could point to anything. | Game classes such as {{hl|WorldEditorAPI}}, {{hl|ScriptEditor}} etc must '''not''' be a strong {{hl|ref}} script-side; on scripts reload, these references are not nulled and could point to anything. | ||
< | {| class="wikitable valign-top" | ||
! Do | |||
! style="min-width: 40em" | Don't | |||
|- | |||
| Get {{hl|WorldEditorAPI}} as a '''method''' variable where needed: | |||
# <enforce> | |||
WorldEditor worldEditor = Workbench.GetModule(WorldEditor); | |||
if (!worldEditor) | |||
return; | |||
WorldEditorAPI worldEditorAPI = worldEditor.GetApi(); | |||
</enforce><!-- | |||
-->or one-lined (no nullcheck)<!-- | |||
--><enforce> | |||
WorldEditorAPI worldEditorAPI = ((WorldEditor)Workbench.GetModule(WorldEditor)).GetApi(); | |||
</enforce> | |||
# <enforce> | |||
WorldEditorAPI worldEditorAPI = SCR_WorldEditorToolHelper.GetWorldEditorAPI(); | |||
</enforce> | |||
# <enforce> | |||
WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI(); // in GenericEntity children | |||
WorldEditorAPI worldEditorAPIFromEntity = anEntity._WB_GetEditorAPI(); // it is public | |||
</enforce> | |||
# <enforce> | |||
m_API; // in WorldEditorTool children | |||
</enforce> | |||
| Store {{hl|WorldEditorAPI}} as a '''class''' pointer: | |||
<enforce> | <enforce> | ||
class TAG_MyClass | class TAG_MyClass | ||
{ | { | ||
WorldEditorAPI m_WorldEditorAPI; // wrong | WorldEditorAPI m_WorldEditorAPI; // wrong | ||
} | } | ||
</enforce> | </enforce> | ||
|} | |||
Line 63: | Line 50: | ||
{{Feature|important| | {{Feature|important| | ||
Editing a {{Link/Enfusion|armaR|BaseContainer}} using {{hl|.Set*}} methods does '''not''' modify the Prefab itself; it modifies the | Editing a {{Link/Enfusion|armaR|BaseContainer}} using {{hl|.Set*}} methods does '''not''' modify the Prefab itself; it only modifies the current instance in memory.<br> | ||
Proper Prefab editing '''always''' happens in {{Link/Enfusion|armaR|WorldEditorAPI}} methods, such as: | Proper Prefab editing '''always''' happens in {{Link/Enfusion|armaR|WorldEditorAPI}} methods, such as: | ||
<enforce> | <enforce> |
Latest revision as of 17:51, 26 September 2024
World Editor API allows for plugin/tool world operations like obtaining terrain resolution, but mostly for Prefab operations such as editing and saving a Prefab (called Entity Template in the API for historical reason – hence the .et extension) using BaseContainer references.
General Usage
Game classes such as WorldEditorAPI, ScriptEditor etc must not be a strong ref script-side; on scripts reload, these references are not nulled and could point to anything.
Do | Don't |
---|---|
Get WorldEditorAPI as a method variable where needed:
|
Store WorldEditorAPI as a class pointer:
|
Prefab Actions
Prefab actions allow editing Prefabs automatically, with or without user input.
Get Prefab
Set Value
values are set as string through WorldEditorAPI in .et files. For example, a true bool value will be represented as 1 in a .et file, therefore "1" must be provided (see bool.ToString(true) for more information).
Direct Value
The SetVariableValue method is used:
Native Type Array
The SetVariableValue method is used, setting values with separating commas:
Object Creation
Two cases are identified: the object can either be a direct object property or an array item.
In the first case (direct object property), the CreateObjectVariableMember method must be used:
In the second case (array element), the CreateObjectArrayVariableMember method is used:
Object Value
To set an object's value, the path parameter, an array of ContainerIdPathEntry must be used:
An array item is accessed using the ContainerIdPathEntry's index parameter, to determine which item is targeted
A component is accessed the same way - using the "components" path:
Delete Value
An array cannot be deleted this way. All its items should be removed through RemoveObjectArrayVariableMember usage instead:
Save Changes
Simply use the following:
Helpers
See also:
- SCR_WorldEditorToolHelper - a helper for WorldEditor/WorldEditorAPI usage
- SCR_PrefabHelper - a helper for various tools's Prefab management