Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"name": "_release",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## v1.8.0
- Added `WeakPointer.replace`, to modify a pointer in-place.

- Trying to overwrite the return value of a void function will now return a more appropriate error.

- The type hinting of `WrappedArray`s now default to `WrappedArray[Any]`, no generic required.

- Upgraded to support unrealsdk v2 - native modules can expect some breakage. The most notable
effect this has on Python code is a number of formerly read-only fields on core unreal types have
become read-write.
Expand Down
2 changes: 1 addition & 1 deletion common_cmake
12 changes: 11 additions & 1 deletion src/pyunrealsdk/unreal_bindings/weak_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ void register_weak_pointer(py::module_& mod) {
"be safe under a hook, since the GC shouldn't be running.\n"
"\n"
"Returns:\n"
" The object this is pointing at, or None if it's become invalid.");
" The object this is pointing at, or None if it's become invalid.")
.def(
"replace", [](WeakPointer& self, const UObject* obj) { self = WeakPointer{obj}; },
"Replaces the reference in this pointer in-place.\n"
"\n"
"This is equivalent to assigning the same variable to a new pointer, but may be\n"
"more convenient when modifying a parent scope.\n"
"\n"
"Args:\n"
" obj: The new object to hold a weak reference to.",
"obj"_a);

// Create as a class method, see pybind11#1693
cls.attr("__class_getitem__") = py::reinterpret_borrow<py::object>(PyClassMethod_New(
Expand Down
11 changes: 11 additions & 0 deletions stubs/unrealsdk/unreal/_weak_pointer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ class WeakPointer[T: UObject = UObject]:
The object this is pointing at, or None if it's become invalid.
"""

def replace(self, obj: T | None) -> None:
"""
Replaces the reference in this pointer in-place.

This is equivalent to assigning the same variable to a new pointer, but may be
more convenient when modifying a parent scope.

Args:
obj: The new object to hold a weak reference to.
"""

@classmethod
def __class_getitem__(cls, *args: Any, **kwargs: Any) -> GenericAlias:
"""
Expand Down
2 changes: 1 addition & 1 deletion stubs/unrealsdk/unreal/_wrapped_array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from typing import Any, Never, Self, overload

from ._uobject_children import UProperty

class WrappedArray[T]:
class WrappedArray[T = Any]:
_type: UProperty

def __add__(self, values: Sequence[T]) -> list[T]:
Expand Down
Loading