Skip to content

Commit 5d1ef0b

Browse files
author
Roberto De Ioris
committed
added first round of tests for blueprint generation
1 parent 2bb8727 commit 5d1ef0b

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

Source/UnrealEnginePython/Private/UEPyEdGraphPin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int py_ue_edgraphpin_set_default_object(ue_PyEdGraphPin *self, PyObject *
9797
self->pin->DefaultObject = py_obj->ue_object;
9898
return 0;
9999
}
100-
PyErr_SetString(PyExc_TypeError, "value is not a string");
100+
PyErr_SetString(PyExc_TypeError, "value is not a UObject");
101101
return -1;
102102
}
103103

tests/test_blueprint.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)