You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -946,6 +946,41 @@ on top of UnrealEnginePythonPrivatePCH.h and rebuild the plugin.
946
946
947
947
As with native threads, do not modify (included deletion) UObjects from non-main threads.
948
948
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.
0 commit comments