-
Notifications
You must be signed in to change notification settings - Fork 750
/
create_user_defined_struct.py
93 lines (70 loc) · 2.88 KB
/
create_user_defined_struct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import unreal_engine as ue
from unreal_engine.classes import StructureFactory
from unreal_engine.structs import StructVariableDescription, EdGraphTerminalType
from unreal_engine.enums import EPinContainerType
from unreal_engine.classes import Pawn, Actor
from unreal_engine.structs import Vector, Rotator, Transform
factory = StructureFactory()
new_struct = factory.factory_create_new('/Game/DumbStruct2')
variable = StructVariableDescription()
variable.VarName = 'AStringArray'
variable.FriendlyName = 'A String Array'
variable.ContainerType = EPinContainerType.Array
variable.ToolTip = 'A tooltip for the string array'
variable.Category = 'string'
# struct_add_variable returns the Guid of the newly created var
new_guid = new_struct.struct_add_variable(variable)
# remove default variable (created by the factory using its Guid)
# wecannot do this before, bacause structs cannot be empty
first_var = new_struct.struct_get_variables()[0]
new_struct.struct_remove_variable(first_var.VarGuid)
variable = StructVariableDescription()
variable.VarName = 'AObjectRef'
variable.FriendlyName = 'A Object Ref'
variable.ToolTip = 'A reference to an object'
variable.Category = 'object'
variable.SubCategoryObject = Pawn
new_struct.struct_add_variable(variable)
variable = StructVariableDescription()
variable.VarName = 'AClassRef'
variable.FriendlyName = 'A Class Ref'
variable.ToolTip = 'A reference to a class'
variable.Category = 'class'
variable.SubCategoryObject = Actor
new_struct.struct_add_variable(variable)
variable = StructVariableDescription()
variable.VarName = 'AVector'
variable.FriendlyName = 'A Vector'
variable.ToolTip = 'A Vector'
variable.Category = 'struct'
variable.SubCategoryObject = Vector
variable.DefaultValue = '17,22,30'
new_struct.struct_add_variable(variable)
variable = StructVariableDescription()
variable.VarName = 'ATransform'
variable.FriendlyName = 'A Transform'
variable.ToolTip = 'A Transform'
variable.Category = 'struct'
variable.SubCategoryObject = Transform
variable.DefaultValue = '17,22,30|30,60,90|1,1,1'
new_struct.struct_add_variable(variable)
variable = StructVariableDescription()
variable.VarName = 'ADictionary'
variable.FriendlyName = 'A Dictionary'
variable.ToolTip = 'A Dictionary'
variable.Category = 'string'
variable.ContainerType = EPinContainerType.Map
# the dictionary value type must be specified with a EdGraphTerminalType struct
terminal_type = EdGraphTerminalType()
terminal_type.TerminalCategory = 'float'
variable.PinValueType = terminal_type
new_guid = new_struct.struct_add_variable(variable)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_up(new_guid)
new_struct.struct_move_variable_down(new_guid)
new_struct.save_package()
for description in new_struct.struct_get_variables():
print(description.as_dict())
ue.open_editor_for_asset(new_struct)