1+ import unreal_engine as ue
2+ from unreal_engine .classes import BlueprintFactory , DirectionalLightComponent , K2Node_Event
3+
4+ import time
5+
6+ # create new blueprint from factory
7+ bpFactory = BlueprintFactory ()
8+ bp = bpFactory .factory_create_new ('/Game/test' + str (int (time .time ())))
9+
10+ # add intensity variable
11+ intensity = ue .blueprint_add_member_variable (bp , 'intensity' , 'float' )
12+ # set its visibility to True
13+ ue .blueprint_set_variable_visibility (bp , 'intensity' , True )
14+
15+ # add directional light component
16+ directLightComponent = ue .add_component_to_blueprint (bp ,DirectionalLightComponent , "Directional_light" )
17+
18+ # add node variables (get) to the graph
19+ intensity_node = bp .UberGraphPages [0 ].graph_add_node_variable_get ('intensity' , None , 200 , 100 )
20+ directional_light_node = bp .UberGraphPages [0 ].graph_add_node_variable_get ('Directional_light' , None , 200 , 0 )
21+
22+ # add the SetIntensity node (from DirectionalLightComponent)
23+ directional_light_set_intensity = bp .UberGraphPages [0 ].graph_add_node_call_function (DirectionalLightComponent .SetIntensity , 400 , 0 )
24+
25+ # link variables
26+ intensity_node .node_find_pin ('intensity' ).make_link_to (directional_light_set_intensity .node_find_pin ('NewIntensity' ))
27+ directional_light_node .node_find_pin ('Directional_light' ).make_link_to (directional_light_set_intensity .node_find_pin ('self' ))
28+
29+ # a commodity function for finding an event node
30+ def get_event_node (event_name ):
31+ for node in bp .UberGraphPages [0 ].Nodes :
32+ if node .is_a (K2Node_Event ):
33+ if node .EventReference .MemberName == event_name :
34+ return node
35+
36+ # get the ReceiveBeginPlay event node
37+ begin_play_node = get_event_node ('ReceiveBeginPlay' )
38+
39+ # link BeginPlay to SetIntensity
40+ begin_play_node .node_find_pin ('then' ).make_link_to (directional_light_set_intensity .node_find_pin ('execute' ))
41+
42+ # compile the blueprint
43+ ue .compile_blueprint (bp )
44+
45+ # open related editor
46+ ue .open_editor_for_asset (bp )
47+
48+ # spawn it
49+ ue .get_editor_world ().actor_spawn (bp .GeneratedClass )
0 commit comments