WorldEditorAPI Usage – Arma Reforger
Lou Montana (talk | contribs) m (Fix category) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
(2 intermediate revisions by the same user not shown) | |||
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> | ||
Line 72: | Line 59: | ||
// etc | // etc | ||
</enforce> | </enforce> | ||
}} | |||
=== Get Prefab === | === Get Prefab === | ||
Line 116: | Line 104: | ||
worldEditorAPI.SetVariableValue(myEntitySource, null, "m_sVariable", sValue); // no .ToString() for string | worldEditorAPI.SetVariableValue(myEntitySource, null, "m_sVariable", sValue); // no .ToString() for string | ||
worldEditorAPI.SetVariableValue(myEntitySource, null, "m_vVariable", vValue.ToString(false)); // .ToString(false) to write it as "0 1 2" and not "<0, 1, 2>" | worldEditorAPI.SetVariableValue(myEntitySource, null, "m_vVariable", vValue.ToString(false)); // .ToString(false) to write it as "0 1 2" and not "<0, 1, 2>" | ||
</enforce> | |||
==== Native Type Array ==== | |||
The {{hl|SetVariableValue}} method is used, setting values with separating commas: | |||
<enforce> | |||
worldEditorAPI.SetVariableValue(myEntitySource, null, "m_aBoolArray", "0,1,0,0,1,1,0,0,0,1,1,0,1,1,1,1,0,1,1,1,0,1,0,1"); | |||
worldEditorAPI.SetVariableValue(myEntitySource, null, "m_aFloatArray", "1.1,2,3.14159"); | |||
worldEditorAPI.SetVariableValue(myEntitySource, null, "m_aIntArray", "1,2,3,4,5,6,-10"); | |||
worldEditorAPI.SetVariableValue(myEntitySource, null, "m_aStringArray", "value1,value2,value3"); // note: commas cannot be escaped, making string with commas NOT supported | |||
worldEditorAPI.SetVariableValue(myEntitySource, null, "m_aVectorArray", "0 1 0,0 0 1,1 0 0"); | |||
</enforce> | </enforce> | ||
Line 192: | Line 190: | ||
</enforce> | </enforce> | ||
<!-- | <!-- | ||
== Terrain Actions == | == Terrain Actions == | ||
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