forked from 20tab/UnrealEnginePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblueprint_example_generator.py
More file actions
49 lines (36 loc) · 1.9 KB
/
blueprint_example_generator.py
File metadata and controls
49 lines (36 loc) · 1.9 KB
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
import unreal_engine as ue
from unreal_engine.classes import BlueprintFactory, DirectionalLightComponent, K2Node_Event
import time
# create new blueprint from factory
bpFactory = BlueprintFactory()
bp = bpFactory.factory_create_new('/Game/test' + str(int(time.time())))
# add intensity variable
intensity = ue.blueprint_add_member_variable(bp, 'intensity', 'float')
# set its visibility to True
ue.blueprint_set_variable_visibility(bp, 'intensity', True)
# add directional light component
directLightComponent = ue.add_component_to_blueprint(bp,DirectionalLightComponent, "Directional_light")
# add node variables (get) to the graph
intensity_node = bp.UberGraphPages[0].graph_add_node_variable_get('intensity', None, 200, 100)
directional_light_node = bp.UberGraphPages[0].graph_add_node_variable_get('Directional_light', None, 200, 0)
# add the SetIntensity node (from DirectionalLightComponent)
directional_light_set_intensity = bp.UberGraphPages[0].graph_add_node_call_function(DirectionalLightComponent.SetIntensity, 400, 0)
# link variables
intensity_node.node_find_pin('intensity').make_link_to(directional_light_set_intensity.node_find_pin('NewIntensity'))
directional_light_node.node_find_pin('Directional_light').make_link_to(directional_light_set_intensity.node_find_pin('self'))
# a commodity function for finding an event node
def get_event_node(event_name):
for node in bp.UberGraphPages[0].Nodes:
if node.is_a(K2Node_Event):
if node.EventReference.MemberName == event_name:
return node
# get the ReceiveBeginPlay event node
begin_play_node = get_event_node('ReceiveBeginPlay')
# link BeginPlay to SetIntensity
begin_play_node.node_find_pin('then').make_link_to(directional_light_set_intensity.node_find_pin('execute'))
# compile the blueprint
ue.compile_blueprint(bp)
# open related editor
ue.open_editor_for_asset(bp)
# spawn it
ue.get_editor_world().actor_spawn(bp.GeneratedClass)