Skip to content

Commit a9547b2

Browse files
author
rdeioris
committed
2 parents 24143a2 + cf3d3cf commit a9547b2

File tree

4 files changed

+573
-44
lines changed

4 files changed

+573
-44
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ The Python VM tries to give easy access to all of the UE4 internal api + its ref
99

1010
It is not meant as a way to avoid blueprints or c++ but as a good companion to them (albeit reducing the amount of c++ required for coding a game could be an interesting thing ;). If your development pipeline is already python-based (Maya, Blender, ...), this plugin could easily help you in integrating unreal into it.
1111

12-
Another funny feature (well, a side effect ;) is that you can change your python code even after the project has been packaged. You can potentially build a completely new game from an already packaged one.
12+
If you want to have an idea of what the plugin can do, jump here: https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/YourFirstAutomatedPipeline.md
1313

1414
In addition to this, the plugin automatically adds an actor class (PyActor), a pawn class (PyPawn), a character class (PyCharacter) and a component class (PythonComponent) for "gentle" integration of python in your games.
1515

16-
In the development menu, you get access to the 'PythonConsole' too, you can use it to trigger python commands directly from the editor. There is even an experimental Editor/IDE included, you can run it from the Window/Layout/Python Editor menu item.
16+
Another funny feature (well, a side effect ;) is that you can change your python code even after the project has been packaged. You can potentially build a completely new game from an already packaged one.
17+
18+
Once the plugin is installed and enabled, you get access to the 'PythonConsole' item in the 'Development Menu', you can use it to trigger python commands directly from the editor. There is even an experimental Editor/IDE included, you can run it from the Window/Layout/Python Editor menu item.
1719

1820
All of the exposed engine features are under the 'unreal_engine' virtual module (it is completely coded in c into the plugin, so do not expect to run 'import unreal_engine' from a standard python shell)
1921

20-
The currently supported Unreal Engine versions are 4.12, 4.13, 4.14 and 4.15
22+
The currently supported Unreal Engine versions are 4.12, 4.13, 4.14, 4.15 and 4.16
2123

2224
# Binary installation on Windows (64 bit)
2325

@@ -47,6 +49,8 @@ git clone https://github.com/20tab/UnrealEnginePython
4749

4850
By default the build procedure will try to discover your python installation looking at hardcoded known paths. If you want to specify a custom python installation (or the autodetection simply fails) you can change it in the Source/UnrealEnginePython/UnrealEnginePython.Build.cs file at this line: https://github.com/20tab/UnrealEnginePython/blob/master/Source/UnrealEnginePython/UnrealEnginePython.Build.cs#L10
4951

52+
Note: ensure you have a 64bit python installation
53+
5054

5155
choose a project you want to install the plugin into, open the file explorer (you can do it from the epic launcher too) and:
5256

tutorials/YourFirstAutomatedPipeline.md

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Your First Automated Pipeline with UnrealEnginePython (WORK IN PROGRESS)
1+
Your First Automated Pipeline with UnrealEnginePython (Part 1)
22
=
33

44
In this tutorial i will try to show you how to build a python script that can generate
5-
a new Unreal Engine 4 Blueprint implementing a Kaiju (a big Japanese monster) with its materials, animations and a simple AI based on Behavior Trees.
5+
a new Unreal Engine 4 Blueprint implementing a Kaiju (a big Japanese monster) with its materials and animations. In the second part a simple AI based on Behavior Trees will be added to the Blueprint as well as a bunch of simple unit tests..
66

77
Running the script from the Unreal Engine Python Console will result in a native Blueprint (as well as meshes, animations, a blackboard and a behaviour tree graph) that does not require the python plugin to work.
88

@@ -77,7 +77,7 @@ ue.py_exec('name_of_script.py')
7777

7878
![First script in console](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/YourFirstAutomatedPipeline_Assets/first_script_console.png)
7979

80-
Finally, download the https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/YourFirstAutomatedPipeline_Assets/Kaiju_Assets.zip file and unzip it in your Desktop folder. These are the original files (fbx, tga, ...) we will import in the project using a python script.
80+
Finally, download the https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/YourFirstAutomatedPipeline_Assets/Kaiju_Assets.zip file and unzip it in your Desktop folder. These are the original files (fbx, tga, ...) we will import in the project using a python script. The files have been 'donated' to me by Matteo Baccaro and Giacomo Caneschi of AIV (Italian Videogame Academy, http://aiv01.it)
8181

8282
Importing the Mesh FBX
8383
-
@@ -133,7 +133,7 @@ The Kaiju original model is 30 meters high, so we scale it down to use it in a c
133133
Creating the Materials
134134
-
135135

136-
The models looks good from a geometry point of view, but you can note (on the top left of the previous screenshot) that no material is assigned to the mesh.
136+
The model looks good from a geometry point of view, but you can note (on the top left of the previous screenshot) that no material is assigned to the mesh.
137137

138138
We are going to create two different materials, one for the blades (Element 0) and the other for the kaiju body (Element 1)
139139

@@ -196,7 +196,7 @@ slicer_texture_orm = texture_factory.factory_import_object(slicer_texture_orm_tg
196196

197197
The textures are ready, we can start "programming" our materials adding nodes to the graphs.
198198

199-
Let's start with the blades. The only two things to take into account is that the OcclusionRoughnessMetallic textures must have the sRGB flag turned off, and each of its channel will be mapped to a different channel:
199+
Let's start with the blades. The only two things to take into account is that the OcclusionRoughnessMetallic textures must have the sRGB flag turned off, and each of its color channel will be mapped to a different material component:
200200

201201
* Green -> Roughness
202202
* Blue -> Metallic
@@ -415,7 +415,10 @@ blend_space_factory.TargetSkeleton = slicer_mesh.Skeleton
415415
# create the asset
416416
slicer_locomotion = blend_space_factory.factory_create_new('/Game/Kaiju/Slicer/Animations/slicer_locomotion')
417417

418+
ue.open_editor_for_asset(slicer_locomotion)
419+
418420
# set blend parameters
421+
slicer_locomotion.modify()
419422
slicer_locomotion.BlendParameters = BlendParameter(DisplayName='Speed', Min=0, Max=300, GridNum=2)
420423

421424
# assign animations
@@ -425,11 +428,12 @@ slicer_locomotion.BlendParameters = BlendParameter(DisplayName='Speed', Min=0, M
425428
# mark them as 'valid' explicitely !
426429
slicer_locomotion.SampleData = [BlendSample(Animation=animation_idle, SampleValue=FVector(0, 0, 0), bIsValid=True, RateScale=1), BlendSample(Animation=animation_walk, SampleValue=FVector(150, 0, 0), bIsValid=True, RateScale=1), BlendSample(Animation=animation_run, SampleValue=FVector(300, 0, 0), bIsValid=True, RateScale=1)]
427430

428-
# save
429-
slicer_locomotion.save_package()
430-
431431
# compute blend space and update the editor preview
432432
slicer_locomotion.post_edit_change()
433+
434+
slicer_locomotion.save_package()
435+
436+
ue.close_editor_for_asset(slicer_locomotion)
433437
```
434438

435439
![The Kaiju Locomotion BlendSpace](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/YourFirstAutomatedPipeline_Assets/slicer_locomotion.png)
@@ -456,17 +460,16 @@ anim_bp_factory = AnimBlueprintFactory()
456460
anim_bp_factory.TargetSkeleton = slicer_mesh.Skeleton
457461

458462
# ensure no blueprint with the same name exists
459-
# get_asset() returns an exception, maybe it is time to implement a asset_exists() api function ?
460-
try:
461-
bp_exists = ue.get_asset('/Game/Kaiju/Slicer/slicer_AnimBP.slicer_AnimBP')
462-
ue.delete_asset(bp_exists.get_path_name())
463-
except:
464-
pass
463+
# find_asset() returns None if the asset does not exist
464+
anim_bp = ue.find_asset('/Game/Kaiju/Slicer/slicer_AnimBP.slicer_AnimBP')
465+
if anim_bp:
466+
ue.delete_asset(anim_bp.get_path_name())
465467

466468
anim_bp = anim_bp_factory.factory_create_new('/Game/Kaiju/Slicer/slicer_AnimBP')
467469
```
468470

469-
unfortunately, as you can see, we need a hack when creating new blueprints. Generating a Blueprint with the same name of another one will trigger a crash. We are investigating a better api to avoid that tricky exception.
471+
Always take into account that creating a Blueprint (of any kind) with a name of an existing one, will trigger an error.
472+
If ue.find_asset() succeeds, we destroy the already existing asset.
470473

471474
Once the blueprint is created, we need to assign a custom event 'DoAttack' (triggered when the Kaiju is near a Pawn), anpther one called 'Boring' (triggered when the kaiju is stationary/idle for more than 10 seconds), 2 bool variables (Attack, Bored) and a float one (Speed):
472475

@@ -752,49 +755,51 @@ Now it is time to create The Character Blueprint at which we will attach the pre
752755
```python
753756
from unreal_engine.classes import Character
754757

758+
# always check for already existing blueprints
759+
slicer_bp = ue.find_asset('/Game/Kaiju/Slicer/slicer_Blueprint.slicer_Blueprint')
760+
if slicer_bp:
761+
ue.delete_asset(slicer_bp.get_path_name())
762+
755763
slicer_bp = ue.create_blueprint(Character, '/Game/Kaiju/Slicer/slicer_Blueprint')
756764
```
757765

766+
time to assign values:
767+
758768
```python
769+
770+
# configure the capsule
759771
slicer_bp.GeneratedClass.get_cdo().CapsuleComponent.CapsuleHalfHeight = 150
760772
slicer_bp.GeneratedClass.get_cdo().CapsuleComponent.CapsuleRadius = 60
773+
774+
# assign the the skeletal mesh and fix its relative position
761775
slicer_bp.GeneratedClass.get_cdo().Mesh.SkeletalMesh = slicer_mesh
762776
slicer_bp.GeneratedClass.get_cdo().Mesh.RelativeLocation = FVector(10, -3, -144)
763-
```
764777

765-
TODO: assign the skeletal mesh, fix the capsule, assign the anim blueprint
778+
# assign the animation blueprint
779+
slicer_bp.GeneratedClass.get_cdo().Mesh.AnimClass = anim_bp.GeneratedClass
780+
```
766781

767-
Filling the Event Graph
768-
-
782+
the get_cdo() method returns the 'Class Default Object', it is a special instance of a class defining the default properties and components that following instances should inherit. When you edit a blueprint class you can effectively editing its 'cdo'.
769783

770-
TODO: implement the idle timer triggering the bored state
771-
772-
The BlackBoard
773-
-
784+
We can now complete the first part of the tutorial by compiling the blueprint:
774785

775786
```python
776-
from unreal_engine.classes import BlackBoardDataFactory
777-
from unreal_engine.classes import BlackboardKeyType_Bool, BlackboardKeyType_String
778-
779-
from unreal_engine.structs import BlackboardEntry
780-
787+
ue.compile_blueprint(slicer_bp)
788+
slicer_bp.save_package()
781789
```
782-
783-
The Behavior Tree Graph
784-
-
785-
786-
TODO: Implement a decorator checking for pawn in a sphere, create a bt with a sequence of 'move to', 'raise event (attack)', 'wait'
787-
788-
The Kaiju Brain
790+
Final notes
789791
-
790792

791-
TODO: assign the bt to the AIController of the Kaiju
793+
You can get the whole script here: https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/YourFirstAutomatedPipeline_Assets/kaiju_slicer_pipeline.py
792794

793-
Testing it
794-
-
795+
You can now drag and drop the blueprint in your scene or subclass it.
795796

796-
TODO: write a unit test instantiating the Kaiju with a dumb pawn and checking for pawn in its virtual sphere.
797+
You can eventually spawn it directly from python:
797798

798-
Final notes
799-
-
799+
```python
800+
# get a reference to the editor world
801+
world = ue.get_editor_world()
802+
world.actor_spawn(slicer_bp.GeneratedClass, FVector(17, 22, 30))
803+
```
800804

805+
In part2 we will see how to give a 'brain' to our Kaiju.

0 commit comments

Comments
 (0)