|
| 1 | +import unittest |
| 2 | +import unreal_engine as ue |
| 3 | +from unreal_engine.classes import Actor, Character |
| 4 | +from unreal_engine import FVector |
| 5 | +import time |
| 6 | +import math |
| 7 | + |
| 8 | +class TestBlueprint(unittest.TestCase): |
| 9 | + |
| 10 | + def setUp(self): |
| 11 | + self.world = ue.get_editor_world() |
| 12 | + self.random_string = str(int(time.time())) |
| 13 | + |
| 14 | + |
| 15 | + def tearDown(self): |
| 16 | + ue.allow_actor_script_execution_in_editor(False) |
| 17 | + |
| 18 | + def test_creation(self): |
| 19 | + new_blueprint = ue.create_blueprint(Actor, '/Game/Tests/Blueprints/Test0_' + self.random_string) |
| 20 | + ue.log(new_blueprint.ParentClass) |
| 21 | + self.assertEqual(new_blueprint.ParentClass, Actor) |
| 22 | + self.assertNotEqual(new_blueprint.ParentClass, Character) |
| 23 | + |
| 24 | + def test_spawn(self): |
| 25 | + new_blueprint = ue.create_blueprint(Character, '/Game/Tests/Blueprints/Test1_' + self.random_string) |
| 26 | + new_actor = self.world.actor_spawn(new_blueprint.GeneratedClass) |
| 27 | + self.assertTrue(new_actor.is_a(Character)) |
| 28 | + |
| 29 | + def test_variable(self): |
| 30 | + new_blueprint = ue.create_blueprint(Character, '/Game/Tests/Blueprints/Test2_' + self.random_string) |
| 31 | + ue.blueprint_add_member_variable(new_blueprint, 'TestValue', 'int') |
| 32 | + ue.compile_blueprint(new_blueprint) |
| 33 | + new_actor = self.world.actor_spawn(new_blueprint.GeneratedClass) |
| 34 | + new_actor.TestValue = 17 |
| 35 | + self.assertEqual(new_actor.get_property('TestValue'), 17) |
| 36 | + |
| 37 | + def test_event(self): |
| 38 | + new_blueprint = ue.create_blueprint(Character, '/Game/Tests/Blueprints/Test3_' + self.random_string) |
| 39 | + uber_page = new_blueprint.UberGraphPages[0] |
| 40 | + x, y = uber_page.graph_get_good_place_for_new_node() |
| 41 | + test_event = uber_page.graph_add_node_custom_event('TestEvent', x, y) |
| 42 | + x, y = uber_page.graph_get_good_place_for_new_node() |
| 43 | + node_set_actor_location = uber_page.graph_add_node_call_function(Actor.K2_SetActorLocation, x, y) |
| 44 | + test_event.node_find_pin('then').make_link_to(node_set_actor_location.node_find_pin('execute')) |
| 45 | + node_set_actor_location.node_find_pin('NewLocation').default_value = '17,30,22' |
| 46 | + ue.compile_blueprint(new_blueprint) |
| 47 | + new_actor = self.world.actor_spawn(new_blueprint.GeneratedClass) |
| 48 | + self.assertEqual(new_actor.get_actor_location(), FVector(0, 0, 0)) |
| 49 | + ue.allow_actor_script_execution_in_editor(True) |
| 50 | + new_actor.TestEvent() |
| 51 | + self.assertEqual(new_actor.get_actor_location(), FVector(17, 30, 22)) |
| 52 | + |
0 commit comments