Skip to content

Commit 74f69b4

Browse files
author
Roberto De Ioris
committed
2 parents dba290e + bbba698 commit 74f69b4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,41 @@ on top of UnrealEnginePythonPrivatePCH.h and rebuild the plugin.
946946

947947
As with native threads, do not modify (included deletion) UObjects from non-main threads.
948948

949+
Accessing Python Proxy From UObject
950+
-----------------------------------
951+
952+
Sometimes you may have a UObject and know that it is backed by a python object. To get the python object from the UObject, use the `get_py_proxy` method. For example, imagine you have the following situation:
953+
954+
1. There is a `PyActor` sub-class called `PyExplosiveActor` which has `Explosive` as its python class.
955+
2. The `Explosive` has a `go_boom` python method.
956+
3. There is a `PyActor` sub-class called `PyBadGuyActor` which has a Blueprint property called `MyBomb` and a python class called `BadGuy`.
957+
4. The `BadGuy` instance in python knows that its UObject has its `MyBomb` as an instance of `PyExplosiveActor` and wants to call the `go_boom` python method.
958+
959+
This would be resolved as shown below:
960+
961+
```
962+
import unreal_engine as ue
963+
964+
class Explosive:
965+
'Python representation for PyExplosiveActor in UE4'
966+
967+
def go_boom(self):
968+
# do python stuff to explode
969+
...
970+
self.uobject.destory()
971+
972+
class BadGuy:
973+
'Python reprsentation for PyBadGuyActor in UE4'
974+
975+
def ignite_bomb(self, delay):
976+
bomb = self.uobject.MyBomb
977+
py_bomb = bomb.get_py_proxy()
978+
py_bomb.go_boom()
979+
980+
```
981+
982+
What is going on here in `BadGuy` is that self.uobject is a reference to the PyActor UObject and `self.uobject.MyBomb` is a reference to the `PyExplosive` uobject. But instead you want to access its proxy class (`Explosive`). The `get_py_proxy()` method returns the python custom class, `Explosive` that the `PyExplosiveActor` object is mapped to.
983+
949984
Status and Known issues
950985
-----------------------
951986

0 commit comments

Comments
 (0)