|
| 1 | +import unreal_engine as ue |
| 2 | +from unreal_engine.classes import K2Node_InputKey, K2Node_SpawnActorFromClass, Actor, Character, KismetMathLibrary |
| 3 | +from unreal_engine.structs import Key |
| 4 | + |
| 5 | +# create a new blueprint |
| 6 | +new_blueprint = ue.create_blueprint(Actor, '/Game/StrangeBlueprint') |
| 7 | + |
| 8 | +# add a member float variable |
| 9 | +ue.blueprint_add_member_variable(new_blueprint, 'Speed', 'float') |
| 10 | + |
| 11 | +# get a reference to the first graph page |
| 12 | +uber_page = new_blueprint.UberGraphPages[0] |
| 13 | + |
| 14 | +# get good coordinates for a new node |
| 15 | +x, y = uber_page.graph_get_good_place_for_new_node() |
| 16 | +# add the Speed variable to the graph |
| 17 | +uber_page.graph_add_node_variable_get('Speed', None, x, y) |
| 18 | + |
| 19 | +x, y = uber_page.graph_get_good_place_for_new_node() |
| 20 | +# add a custom event to the graph |
| 21 | +hello_world = uber_page.graph_add_node_custom_event('Hello World', x, y) |
| 22 | + |
| 23 | +# get a reference to the 'then' pin |
| 24 | +hello_world_then = hello_world.node_find_pin('then') |
| 25 | + |
| 26 | +x, y = uber_page.graph_get_good_place_for_new_node() |
| 27 | +# add a 'Spawn Actor From Class' node |
| 28 | +spawn_actor_node = uber_page.graph_add_node(K2Node_SpawnActorFromClass, x, y) |
| 29 | + |
| 30 | +# set its Class pin |
| 31 | +pin_class = spawn_actor_node.node_find_pin('Class') |
| 32 | +pin_class.default_object = Character |
| 33 | + |
| 34 | +# get a reference to its 'exec' pin |
| 35 | +spawn_actor_node_exec = spawn_actor_node.node_find_pin('execute') |
| 36 | + |
| 37 | +# link the hello world event to the spawn actor node |
| 38 | +hello_world_then.make_link_to(spawn_actor_node_exec) |
| 39 | + |
| 40 | +x, y = uber_page.graph_get_good_place_for_new_node() |
| 41 | +# create a 'make transform' node |
| 42 | +make_transform = uber_page.graph_add_node_call_function(KismetMathLibrary.MakeTransform, x, y) |
| 43 | + |
| 44 | +# link the return value of 'make transform' to the 'SpawnTransform' pin of the spawn actor node |
| 45 | +make_transform.node_find_pin('ReturnValue').make_link_to(spawn_actor_node.node_find_pin('SpawnTransform')) |
| 46 | + |
| 47 | +input_key = K2Node_InputKey(Outer=uber_page) |
| 48 | +input_key.InputKey = Key(KeyName='SpaceBar') |
| 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