1+ from enum import IntFlag , auto
12from functools import wraps
23from pathlib import Path
3- from typing import Literal , overload
4+ from typing import TYPE_CHECKING , Literal , overload
45
56import unrealsdk
67from unrealsdk .unreal import UObject
@@ -126,6 +127,21 @@ def get_pc(*, possibly_loading: bool = False) -> UObject | None:
126127 raise NotImplementedError
127128
128129
130+ class ObjectFlags (IntFlag ):
131+ """
132+ Useful values to assign to object flags, both for directly on an object and in construct_object.
133+
134+ Note that not all flags are known in all games - though the type hinting always contains them
135+ all. Trying to use a flag in a game where it's not known will throw an attribute error.
136+ """
137+
138+ if TYPE_CHECKING :
139+ # Prevents the object from getting garbage collected
140+ KEEP_ALIVE = auto ()
141+ # Allows the object to be referenced by objects in other packages
142+ ALLOW_CROSS_PACKAGE_REFERENCES = auto ()
143+
144+
129145match Game .get_tree ():
130146 case Game .Willow1 | Game .Willow2 :
131147 ENGINE = unrealsdk .find_object ( # pyright: ignore[reportConstantRedefinition]
@@ -142,6 +158,13 @@ def get_pc_willow(*, possibly_loading: bool = False) -> UObject | None: # noqa:
142158
143159 get_pc = get_pc_willow # type: ignore
144160
161+ @wraps (ObjectFlags , updated = ())
162+ class WillowObjectFlags (ObjectFlags ): # type: ignore
163+ ALLOW_CROSS_PACKAGE_REFERENCES = 0x4
164+ KEEP_ALIVE = 0x4000
165+
166+ ObjectFlags = WillowObjectFlags # type: ignore
167+
145168 case Game .Oak :
146169 ENGINE = unrealsdk .find_object ( # pyright: ignore[reportConstantRedefinition]
147170 "OakGameEngine" ,
@@ -163,3 +186,9 @@ def get_pc_oak(*, possibly_loading: bool = False) -> UObject | None: # noqa: AR
163186 )
164187
165188 get_pc = get_pc_oak # type: ignore
189+
190+ @wraps (ObjectFlags , updated = ())
191+ class OakObjectFlags (ObjectFlags ): # type: ignore
192+ KEEP_ALIVE = 0x80
193+
194+ ObjectFlags = OakObjectFlags # type: ignore
0 commit comments