Skip to content

Commit 2ce96e5

Browse files
committed
add copy methods to wrapped struct
1 parent 1354f59 commit 2ce96e5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,22 @@ void register_wrapped_struct(py::module_& mod) {
212212
" field: The field to set.\n"
213213
" value: The value to write.",
214214
"field"_a, "value"_a)
215+
.def(
216+
"__copy__", [](const WrappedStruct& self) { return WrappedStruct(self); },
217+
"Creates a copy of this struct. Don't call this directly, use copy.copy().\n"
218+
"\n"
219+
"Returns:\n"
220+
" A new, python-owned copy of this struct.")
221+
.def(
222+
"__deepcopy__",
223+
[](const WrappedStruct& self, const py::dict& /*memo*/) { return WrappedStruct(self); },
224+
"Creates a copy of this struct. Don't call this directly, use copy.deepcopy().\n"
225+
"\n"
226+
"Args:\n"
227+
" memo: Opaque dict used by deepcopy internals."
228+
"Returns:\n"
229+
" A new, python-owned copy of this struct.",
230+
"memo"_a)
215231
.def_readwrite("_type", &WrappedStruct::type);
216232
}
217233

stubs/unrealsdk/unreal/_wrapped_struct.pyi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ from ._uobject_children import UField, UFunction, UScriptStruct, UStruct
77
class WrappedStruct:
88
_type: UStruct
99

10+
def __copy__(self) -> WrappedStruct:
11+
"""
12+
Creates a copy of this struct. Don't call this directly, use copy.copy().
13+
14+
Returns:
15+
A new, python-owned copy of this struct.
16+
"""
17+
18+
def __deepcopy__(self, memo: dict[Any, Any]) -> WrappedStruct:
19+
"""
20+
Creates a copy of this struct. Don't call this directly, use copy.deepcopy().
21+
22+
Args:
23+
memo: Opaque dict used by deepcopy internal
24+
Returns:
25+
A new, python-owned copy of this struct.
26+
"""
27+
1028
def __dir__(self) -> list[str]:
1129
"""
1230
Gets the attributes which exist on this struct.

0 commit comments

Comments
 (0)