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
Here we are seeing two different behaviours between factory and texture. The first one survived the GC run, the second has been destroyed.
53
+
54
+
This is because only UObject's created explicitely by Python with a classic constructor (like BlueprintFactory()) are bound to the related ue_PyUObject. All of the others obey the Unreal GC rules. This is a pretty complex choice aimed at improving performance and avoiding too much competition between the two GCs.
55
+
49
56
Very long scripts, that do lot of stuff, often triggering UE4 GC, could be blocked in the middle of their execution by this kind of errors. In such a case (like you would do in C++) you need to inform the UE GC on how to deal with them (for avoiding their destruction).
50
57
51
58
Pay attention, as once you tell the UE GC to not destroy a UObject, that UObject (and its python mapping) will stay in memory (so you will end with a leak)
@@ -61,15 +68,13 @@ You can change this bitmask with the set_obj_flags() python function:
61
68
```python
62
69
import unreal_engine as ue
63
70
64
-
from unreal_engine.classes import BlueprintFactory
# the second True argument will reset the flags (otherwise set_obj_flags will work in append mode)
93
96
# eventually you can call factory.reset_obj_flags()
94
-
factory.set_obj_flags(ue.RF_PUBLIC, True)
97
+
texture.set_obj_flags(ue.RF_PUBLIC, True)
95
98
96
99
ue.console_exec('obj gc')
97
100
98
-
print(factory)
101
+
print(texture)
99
102
```
100
103
101
104
The second print will raise the error.
@@ -109,20 +112,18 @@ The root set is a very specific part of the GC tree. If you want to hold control
109
112
```python
110
113
import unreal_engine as ue
111
114
112
-
from unreal_engine.classes import BlueprintFactory
113
-
114
-
factory = BlueprintFactory()
115
-
factory.add_to_root()
115
+
texture = ue.create_transient_texture(512, 512)
116
+
texture.add_to_root()
116
117
117
118
ue.console_exec('obj gc')
118
119
119
-
print(factory)
120
+
print(texture)
120
121
121
-
factory.remove_from_root()
122
+
texture.remove_from_root()
122
123
123
124
ue.console_exec('obj gc')
124
125
125
-
print(factory)
126
+
print(texture)
126
127
```
127
128
128
129
as before, the first GC run will not destroy the UObject (as it is in the root set), while the second one will remove if from the memory as it is no more in the root set.
@@ -150,7 +151,7 @@ tracker = Tracker()
150
151
Now you can create UObject from python and track them automatically. When the python GC destroys the tracker object, all of the UObject's tracked by it will be destroyed too:
As an example when running a script multiple times, the 'tracker' id will be overwritten, triggering the destruction of the mapped python object (and its ```__del__``` method)
0 commit comments