Skip to content

Commit bd416d0

Browse files
author
rdeioris
authored
Create graphs_creator.py
1 parent 6939eda commit bd416d0

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

examples/graphs_creator.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import unreal_engine as ue
2+
from unreal_engine.classes import K2Node_InputKey, K2Node_SpawnActorFromClass, Actor, Character, KismetMathLibrary
3+
4+
# create a new blueprint
5+
new_blueprint = ue.create_blueprint(Actor, '/Game/StrangeBlueprint')
6+
7+
# add a member float variable
8+
ue.blueprint_add_member_variable(new_blueprint, 'Speed', 'float')
9+
10+
# get a reference to the first graph page
11+
uber_page = new_blueprint.UberGraphPages[0]
12+
13+
# get good coordinates for a new node
14+
x, y = uber_page.graph_get_good_place_for_new_node()
15+
# add the Speed variable to the graph
16+
uber_page.graph_add_node_variable_get('Speed', None, x, y)
17+
18+
x, y = uber_page.graph_get_good_place_for_new_node()
19+
# add a custom event to the graph
20+
hello_world = uber_page.graph_add_node_custom_event('Hello World', x, y)
21+
22+
# get a reference to the 'then' pin
23+
hello_world_then = hello_world.node_find_pin('then')
24+
25+
x, y = uber_page.graph_get_good_place_for_new_node()
26+
# add a 'Spawn Actor From Class' node
27+
spawn_actor_node = uber_page.graph_add_node(K2Node_SpawnActorFromClass, x, y)
28+
29+
# set its Class pin
30+
pin_class = spawn_actor_node.node_find_pin('Class')
31+
pin_class.default_object = Character
32+
33+
# get a reference to its 'exec' pin
34+
spawn_actor_node_exec = spawn_actor_node.node_find_pin('execute')
35+
36+
# link the hello world event to the spawn actor node
37+
hello_world_then.make_link_to(spawn_actor_node_exec)
38+
39+
x, y = uber_page.graph_get_good_place_for_new_node()
40+
# create a 'make transform' node
41+
make_transform = uber_page.graph_add_node_call_function(KismetMathLibrary.MakeTransform, x, y)
42+
43+
# link the return value of 'make transform' to the 'SpawnTransform' pin of the spawn actor node
44+
make_transform.node_find_pin('ReturnValue').make_link_to(spawn_actor_node.node_find_pin('SpawnTransform'))
45+
46+
input_key = K2Node_InputKey()
47+
# TODO implement the FKey struct
48+
#input_key.InputKey = ???
49+
input_key_node = uber_page.graph_add_node(input_key, 400, 400)
50+
51+
# compile the blueprint
52+
ue.compile_blueprint(new_blueprint)
53+
54+
# save it
55+
ue.editor_save_all()

0 commit comments

Comments
 (0)