diff --git a/Source/UnrealEnginePython/Private/PyActor.cpp b/Source/UnrealEnginePython/Private/PyActor.cpp index de02331a5..cd1a0bcff 100644 --- a/Source/UnrealEnginePython/Private/PyActor.cpp +++ b/Source/UnrealEnginePython/Private/PyActor.cpp @@ -12,10 +12,9 @@ APyActor::APyActor() } -void APyActor::PostInitializeComponents() +void APyActor::PreInitializeComponents() { - Super::PostInitializeComponents(); - + Super::PreInitializeComponents(); if (PythonModule.IsEmpty()) return; @@ -73,6 +72,25 @@ void APyActor::PostInitializeComponents() ue_bind_events_for_py_class_by_attribute(this, py_actor_instance); + if (!PyObject_HasAttrString(py_actor_instance, (char *)"pre_initialize_components")) + return; + + PyObject *pic_ret = PyObject_CallMethod(py_actor_instance, (char *)"pre_initialize_components", NULL); + if (!pic_ret) { + unreal_engine_py_log_error(); + return; + } + Py_DECREF(pic_ret); +} + + +void APyActor::PostInitializeComponents() +{ + Super::PostInitializeComponents(); + + if (!py_actor_instance) + return; + if (!PyObject_HasAttrString(py_actor_instance, (char *)"post_initialize_components")) return; diff --git a/Source/UnrealEnginePython/Private/UEPyModule.cpp b/Source/UnrealEnginePython/Private/UEPyModule.cpp index 13164a54b..a60a36a4e 100644 --- a/Source/UnrealEnginePython/Private/UEPyModule.cpp +++ b/Source/UnrealEnginePython/Private/UEPyModule.cpp @@ -159,6 +159,7 @@ static PyMethodDef unreal_engine_methods[] = { { "compress_image_array", py_unreal_engine_compress_image_array, METH_VARARGS, "" }, { "create_checkerboard_texture", py_unreal_engine_create_checkerboard_texture, METH_VARARGS, "" }, { "create_transient_texture", py_unreal_engine_create_transient_texture, METH_VARARGS, "" }, + { "create_transient_texture_render_target2d", py_unreal_engine_create_transient_texture_render_target2d, METH_VARARGS, "" }, { "create_world", py_unreal_engine_create_world, METH_VARARGS, "" }, @@ -290,7 +291,7 @@ static PyMethodDef unreal_engine_methods[] = { { "get_game_viewport_client", py_unreal_engine_get_game_viewport_client, METH_VARARGS, "" }, #pragma warning(suppress: 4191) - { "open_color_picker", (PyCFunction)py_unreal_engine_open_color_picker, METH_VARARGS| METH_KEYWORDS, "" }, + { "open_color_picker", (PyCFunction)py_unreal_engine_open_color_picker, METH_VARARGS | METH_KEYWORDS, "" }, { "destroy_color_picker", py_unreal_engine_destroy_color_picker, METH_VARARGS, "" }, { "play_sound", py_unreal_engine_play_sound, METH_VARARGS, "" }, #if WITH_EDITOR @@ -406,7 +407,7 @@ static PyMethodDef ue_PyUObject_methods[] = { { "set_actor_label", (PyCFunction)py_ue_set_actor_label, METH_VARARGS, "" }, { "get_editor_world_counterpart_actor", (PyCFunction)py_ue_get_editor_world_counterpart_actor, METH_VARARGS, "" }, - + { "find_actor_by_label", (PyCFunction)py_ue_find_actor_by_label, METH_VARARGS, "" }, { "save_package", (PyCFunction)py_ue_save_package, METH_VARARGS, "" }, { "asset_can_reimport", (PyCFunction)py_ue_asset_can_reimport, METH_VARARGS, "" }, @@ -437,6 +438,7 @@ static PyMethodDef ue_PyUObject_methods[] = { { "is_rooted", (PyCFunction)py_ue_is_rooted, METH_VARARGS, "" }, { "add_to_root", (PyCFunction)py_ue_add_to_root, METH_VARARGS, "" }, + { "auto_root", (PyCFunction)py_ue_auto_root, METH_VARARGS, "" }, { "remove_from_root", (PyCFunction)py_ue_remove_from_root, METH_VARARGS, "" }, { "find_function", (PyCFunction)py_ue_find_function, METH_VARARGS, "" }, @@ -498,6 +500,8 @@ static PyMethodDef ue_PyUObject_methods[] = { { "hud_draw_2d_line", (PyCFunction)py_ue_hud_draw_2d_line, METH_VARARGS, "" }, { "hud_draw_line", (PyCFunction)py_ue_hud_draw_line, METH_VARARGS, "" }, { "hud_draw_texture", (PyCFunction)py_ue_hud_draw_texture, METH_VARARGS, "" }, + { "hud_draw_rect", (PyCFunction)py_ue_hud_draw_rect, METH_VARARGS, "" }, + { "hud_draw_text", (PyCFunction)py_ue_hud_draw_text, METH_VARARGS, "" }, // Movements @@ -527,6 +531,8 @@ static PyMethodDef ue_PyUObject_methods[] = { { "component_is_registered", (PyCFunction)py_ue_component_is_registered, METH_VARARGS, "" }, { "register_component", (PyCFunction)py_ue_register_component, METH_VARARGS, "" }, + { "unregister_component", (PyCFunction)py_ue_unregister_component, METH_VARARGS, "" }, + { "destroy_component", (PyCFunction)py_ue_destroy_component, METH_VARARGS, "" }, { "actor_destroy_component", (PyCFunction)py_ue_actor_destroy_component, METH_VARARGS, "" }, { "destroy_actor_component", (PyCFunction)py_ue_actor_destroy_component, METH_VARARGS, "" }, @@ -554,7 +560,8 @@ static PyMethodDef ue_PyUObject_methods[] = { { "actor_has_component_of_type", (PyCFunction)py_ue_actor_has_component_of_type, METH_VARARGS, "" }, { "actor_destroy", (PyCFunction)py_ue_actor_destroy, METH_VARARGS, "" }, - { "actor_spawn", (PyCFunction)py_ue_actor_spawn, METH_VARARGS, "" }, +#pragma warning(suppress: 4191) + { "actor_spawn", (PyCFunction)py_ue_actor_spawn, METH_VARARGS | METH_KEYWORDS, "" }, { "actor_has_tag", (PyCFunction)py_ue_actor_has_tag, METH_VARARGS, "" }, { "get_actor_bounds", (PyCFunction)py_ue_get_actor_bounds, METH_VARARGS, "" }, @@ -579,6 +586,8 @@ static PyMethodDef ue_PyUObject_methods[] = { { "get_actor_components_by_type", (PyCFunction)py_ue_get_actor_components_by_type, METH_VARARGS, "" }, { "get_components_by_type", (PyCFunction)py_ue_get_actor_components_by_type, METH_VARARGS, "" }, + { "add_python_component", (PyCFunction)py_ue_add_python_component, METH_VARARGS, "" }, + { "set_simulate_physics", (PyCFunction)py_ue_set_simulate_physics, METH_VARARGS, "" }, { "add_impulse", (PyCFunction)py_ue_add_impulse, METH_VARARGS, "" }, { "add_angular_impulse", (PyCFunction)py_ue_add_angular_impulse, METH_VARARGS, "" }, @@ -588,7 +597,7 @@ static PyMethodDef ue_PyUObject_methods[] = { { "get_physics_linear_velocity", (PyCFunction)py_ue_get_physics_linear_velocity, METH_VARARGS, "" }, { "set_physics_angular_velocity", (PyCFunction)py_ue_set_physics_angular_velocity, METH_VARARGS, "" }, { "get_physics_angular_velocity", (PyCFunction)py_ue_get_physics_angular_velocity, METH_VARARGS, "" }, - { "find_object", (PyCFunction)py_ue_find_object, METH_VARARGS, "" }, + { "find_object", (PyCFunction)py_ue_find_object, METH_VARARGS, "" }, { "get_world", (PyCFunction)py_ue_get_world, METH_VARARGS, "" }, { "has_world", (PyCFunction)py_ue_has_world, METH_VARARGS, "" }, @@ -597,8 +606,8 @@ static PyMethodDef ue_PyUObject_methods[] = { { "get_world_location_at_distance_along_spline", (PyCFunction)py_ue_get_world_location_at_distance_along_spline, METH_VARARGS, "" }, { "get_spline_length", (PyCFunction)py_ue_get_spline_length, METH_VARARGS, "" }, - // Widget - { "take_widget", (PyCFunction)py_ue_take_widget, METH_VARARGS, "" }, + // Widget + { "take_widget", (PyCFunction)py_ue_take_widget, METH_VARARGS, "" }, // WidgetComponent { "set_slate_widget", (PyCFunction)py_ue_set_slate_widget, METH_VARARGS, "" }, @@ -622,6 +631,7 @@ static PyMethodDef ue_PyUObject_methods[] = { { "get_num_spectators", (PyCFunction)py_ue_get_num_spectators, METH_VARARGS, "" }, { "get_player_controller", (PyCFunction)py_ue_get_player_controller, METH_VARARGS, "" }, { "get_player_hud", (PyCFunction)py_ue_get_player_hud, METH_VARARGS, "" }, + { "set_player_hud", (PyCFunction)py_ue_set_player_hud, METH_VARARGS, "" }, { "get_player_camera_manager", (PyCFunction)py_ue_get_player_camera_manager, METH_VARARGS, "" }, { "get_player_pawn", (PyCFunction)py_ue_get_player_pawn, METH_VARARGS, "" }, @@ -671,6 +681,7 @@ static PyMethodDef ue_PyUObject_methods[] = { { "texture_get_width", (PyCFunction)py_ue_texture_get_width, METH_VARARGS, "" }, { "texture_get_height", (PyCFunction)py_ue_texture_get_height, METH_VARARGS, "" }, { "render_target_get_data", (PyCFunction)py_ue_render_target_get_data, METH_VARARGS, "" }, + { "texture_update_resource", (PyCFunction)py_ue_texture_update_resource, METH_VARARGS, "" }, // Sequencer { "sequencer_master_tracks", (PyCFunction)py_ue_sequencer_master_tracks, METH_VARARGS, "" }, @@ -749,12 +760,16 @@ void ue_pydelegates_cleanup(ue_PyUObject *self) { UE_LOG(LogPython, Warning, TEXT("Removing UPythonDelegate %p from ue_PyUObject %p mapped to UObject %p"), py_delegate, self, self->ue_object); #endif py_delegate->RemoveFromRoot(); + } } -} self->python_delegates_gc->clear(); delete self->python_delegates_gc; self->python_delegates_gc = nullptr; + if (self->auto_rooted && self->ue_object->IsRooted()) { + self->ue_object->RemoveFromRoot(); + } + Py_XDECREF(self->py_dict); } @@ -826,8 +841,8 @@ static PyObject *ue_PyUObject_getattro(ue_PyUObject *self, PyObject *attr_name) return PyLong_FromLong(u_enum->FindEnumIndex(item.Key)); #endif } - } } + } #endif if (self->ue_object->IsA()) { UEnum *u_enum = (UEnum *)self->ue_object; @@ -837,15 +852,15 @@ static PyObject *ue_PyUObject_getattro(ue_PyUObject *self, PyObject *attr_name) #else return PyLong_FromLong(u_enum->FindEnumIndex(FName(UTF8_TO_TCHAR(attr)))); #endif - } - } + } + } if (function) { // swallow previous exception PyErr_Clear(); return py_ue_new_callable(function, self->ue_object); } - } +} } return ret; } @@ -1460,7 +1475,7 @@ void unreal_engine_py_log_error() { PyObject *zero = PyUnicode_AsUTF8String(PyObject_Str(value)); if (zero) { msg = PyBytes_AsString(zero); - } +} #else msg = PyString_AsString(PyObject_Str(value)); #endif diff --git a/Source/UnrealEnginePython/Private/UEPyModule.h b/Source/UnrealEnginePython/Private/UEPyModule.h index c7b3802f3..63db52acc 100644 --- a/Source/UnrealEnginePython/Private/UEPyModule.h +++ b/Source/UnrealEnginePython/Private/UEPyModule.h @@ -10,14 +10,16 @@ typedef struct { PyObject_HEAD - /* Type-specific fields go here. */ - UObject *ue_object; + /* Type-specific fields go here. */ + UObject *ue_object; // reference to proxy class (can be null) PyObject *py_proxy; // list of exposed delegates std::list *python_delegates_gc; // the __dict__ PyObject *py_dict; + // if true RemoveFromRoot will be called at object destruction time + int auto_rooted; } ue_PyUObject; diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyActor.cpp b/Source/UnrealEnginePython/Private/UObject/UEPyActor.cpp index 84ba24ba9..080fca230 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyActor.cpp +++ b/Source/UnrealEnginePython/Private/UObject/UEPyActor.cpp @@ -2,6 +2,8 @@ #include "Runtime/LevelSequence/Public/LevelSequenceActor.h" #include "Runtime/LevelSequence/Public/LevelSequence.h" +#include "PythonComponent.h" +#include "UEPyObject.h" PyObject *py_ue_actor_has_tag(ue_PyUObject * self, PyObject * args) { @@ -309,6 +311,30 @@ PyObject *py_ue_setup_attachment(ue_PyUObject *self, PyObject * args) { Py_RETURN_NONE; } +PyObject *py_ue_unregister_component(ue_PyUObject * self, PyObject * args) { + ue_py_check(self); + + UActorComponent *component = ue_py_check_type(self); + if (!component) + return PyErr_Format(PyExc_Exception, "uobject is not an UActorComponent"); + + component->UnregisterComponent(); + + Py_RETURN_NONE; +} + +PyObject *py_ue_destroy_component(ue_PyUObject * self, PyObject * args) { + ue_py_check(self); + + UActorComponent *component = ue_py_check_type(self); + if (!component) + return PyErr_Format(PyExc_Exception, "uobject is not an UActorComponent"); + + component->DestroyComponent(); + + Py_RETURN_NONE; +} + PyObject *py_ue_add_actor_component(ue_PyUObject * self, PyObject * args) { ue_py_check(self); @@ -369,7 +395,40 @@ PyObject *py_ue_add_actor_component(ue_PyUObject * self, PyObject * args) { return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); Py_INCREF(ret); return ret; +} + +PyObject *py_ue_add_python_component(ue_PyUObject * self, PyObject * args) { + + ue_py_check(self); + + char *name; + char *module_name; + char *class_name; + if (!PyArg_ParseTuple(args, "sss:add_python_component", &name, &module_name, &class_name)) { + return NULL; + } + AActor *actor = ue_py_check_type(self); + if (!actor) { + return PyErr_Format(PyExc_Exception, "uobject is not an AActor"); + } + + UPythonComponent *component = NewObject(actor, FName(UTF8_TO_TCHAR(name))); + if (!component) + return PyErr_Format(PyExc_Exception, "unable to create component"); + + component->PythonModule = FString(UTF8_TO_TCHAR(module_name)); + component->PythonClass = FString(UTF8_TO_TCHAR(class_name)); + + if (actor->GetWorld()) { + component->RegisterComponent(); + } + + PyObject *ret = (PyObject *)ue_get_python_wrapper(component); + if (!ret) + return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); + Py_INCREF(ret); + return ret; } PyObject *py_ue_actor_create_default_subobject(ue_PyUObject * self, PyObject * args) { @@ -580,7 +639,7 @@ PyObject *py_ue_get_actor_components_by_type(ue_PyUObject * self, PyObject * arg } -PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args) { +PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args, PyObject *kwargs) { ue_py_check(self); @@ -629,9 +688,39 @@ PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args) { rotation = py_rotation->rot; } - AActor *actor = world->SpawnActor((UClass *)py_obj->ue_object, &location, &rotation); + AActor *actor = nullptr; + PyObject *ret = nullptr; + + if (kwargs && PyDict_Size(kwargs) > 0) { + FTransform transform; + transform.SetTranslation(location); + transform.SetRotation(rotation.Quaternion()); + actor = world->SpawnActorDeferred((UClass *)py_obj->ue_object, transform); + if (!actor) + return PyErr_Format(PyExc_Exception, "unable to spawn a new Actor"); + ue_PyUObject *py_u_obj = ue_get_python_wrapper(actor); + if (!py_u_obj) + return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); + + PyObject *py_iter = PyObject_GetIter(kwargs); + + while (PyObject *py_key = PyIter_Next(py_iter)) { + PyObject *void_ret = py_ue_set_property(py_u_obj, Py_BuildValue("OO", py_key, PyDict_GetItem(kwargs, py_key))); + if (!void_ret) { + return PyErr_Format(PyExc_Exception, "unable to set property for new Actor"); + } + } + Py_DECREF(py_iter); + UGameplayStatics::FinishSpawningActor(actor, transform); + ret = (PyObject *)py_u_obj; + } + else { + actor = world->SpawnActor((UClass *)py_obj->ue_object, &location, &rotation); + if (!actor) + return PyErr_Format(PyExc_Exception, "unable to spawn a new Actor"); + ret = (PyObject *)ue_get_python_wrapper(actor); + } - PyObject *ret = (PyObject *)ue_get_python_wrapper(actor); if (!ret) return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); Py_INCREF(ret); diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyActor.h b/Source/UnrealEnginePython/Private/UObject/UEPyActor.h index 78c99e043..1b880b94c 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyActor.h +++ b/Source/UnrealEnginePython/Private/UObject/UEPyActor.h @@ -20,15 +20,18 @@ PyObject *py_ue_get_editor_world_counterpart_actor(ue_PyUObject *, PyObject *); #endif PyObject *py_ue_get_owner(ue_PyUObject *, PyObject *); PyObject *py_ue_add_actor_component(ue_PyUObject *, PyObject *); +PyObject *py_ue_add_python_component(ue_PyUObject *, PyObject *); PyObject *py_ue_add_actor_root_component(ue_PyUObject *, PyObject *); PyObject *py_ue_actor_has_component_of_type(ue_PyUObject *, PyObject *); PyObject *py_ue_get_actor_component_by_type(ue_PyUObject *, PyObject *); PyObject *py_ue_get_actor_components_by_type(ue_PyUObject *, PyObject *); -PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject *); +PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject *, PyObject *); PyObject *py_ue_get_overlapping_actors(ue_PyUObject *, PyObject *); PyObject *py_ue_actor_destroy_component(ue_PyUObject *, PyObject *); PyObject *py_ue_register_component(ue_PyUObject * self, PyObject *); +PyObject *py_ue_unregister_component(ue_PyUObject * self, PyObject *); +PyObject *py_ue_destroy_component(ue_PyUObject * self, PyObject *); PyObject *py_ue_component_is_registered(ue_PyUObject * self, PyObject *); PyObject *py_ue_actor_create_default_subobject(ue_PyUObject * self, PyObject *); \ No newline at end of file diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyHUD.cpp b/Source/UnrealEnginePython/Private/UObject/UEPyHUD.cpp index d6d3820af..93b5a2d23 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyHUD.cpp +++ b/Source/UnrealEnginePython/Private/UObject/UEPyHUD.cpp @@ -50,6 +50,57 @@ PyObject *py_ue_hud_draw_line(ue_PyUObject *self, PyObject * args) { Py_RETURN_NONE; } +PyObject *py_ue_hud_draw_rect(ue_PyUObject *self, PyObject * args) { + + ue_py_check(self); + + float x, y, w, h; + PyObject *py_fcolor; + + if (!PyArg_ParseTuple(args, "ffffO:hud_draw_line", &x, &y, &w, &h, &py_fcolor)) { + return nullptr; + } + + AHUD *hud = ue_py_check_type(self); + if (!hud) + return PyErr_Format(PyExc_Exception, "UObject is not a AHUD."); + + ue_PyFLinearColor *fcolor = py_ue_is_flinearcolor(py_fcolor); + if (!fcolor) + return PyErr_Format(PyExc_Exception, "argument is not a FColor."); + + hud->DrawRect(fcolor->color, x, y, w, h); + + Py_RETURN_NONE; +} + + +PyObject *py_ue_hud_draw_text(ue_PyUObject *self, PyObject * args) { + + ue_py_check(self); + + char *text; + float x, y; + PyObject *py_fcolor; + float scale = 1; + + if (!PyArg_ParseTuple(args, "sffO|f:hud_draw_text", &text, &x, &y, &py_fcolor, &scale)) { + return nullptr; + } + + AHUD *hud = ue_py_check_type(self); + if (!hud) + return PyErr_Format(PyExc_Exception, "UObject is not a AHUD."); + + ue_PyFLinearColor *fcolor = py_ue_is_flinearcolor(py_fcolor); + if (!fcolor) + return PyErr_Format(PyExc_Exception, "argument is not a FColor."); + + hud->DrawText(FString(UTF8_TO_TCHAR(text)), fcolor->color, x, y, nullptr, scale); + + Py_RETURN_NONE; +} + PyObject *py_ue_hud_draw_texture(ue_PyUObject *self, PyObject * args) { ue_py_check(self); diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyHUD.h b/Source/UnrealEnginePython/Private/UObject/UEPyHUD.h index 0462f42c2..d39041f90 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyHUD.h +++ b/Source/UnrealEnginePython/Private/UObject/UEPyHUD.h @@ -6,4 +6,6 @@ PyObject *py_ue_hud_draw_2d_line(ue_PyUObject *self, PyObject * args); PyObject *py_ue_hud_draw_line(ue_PyUObject *self, PyObject * args); -PyObject *py_ue_hud_draw_texture(ue_PyUObject *self, PyObject * args); \ No newline at end of file +PyObject *py_ue_hud_draw_texture(ue_PyUObject *self, PyObject * args); +PyObject *py_ue_hud_draw_text(ue_PyUObject *self, PyObject * args); +PyObject *py_ue_hud_draw_rect(ue_PyUObject *self, PyObject * args); \ No newline at end of file diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp b/Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp index aa056155c..270ebaf7f 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp +++ b/Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp @@ -701,6 +701,16 @@ PyObject *py_ue_add_to_root(ue_PyUObject *self, PyObject * args) { return Py_None; } +PyObject *py_ue_auto_root(ue_PyUObject *self, PyObject * args) { + + ue_py_check(self); + + self->ue_object->AddToRoot(); + self->auto_rooted = 1; + + Py_RETURN_NONE; +} + PyObject *py_ue_remove_from_root(ue_PyUObject *self, PyObject * args) { ue_py_check(self); diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyObject.h b/Source/UnrealEnginePython/Private/UObject/UEPyObject.h index 6b7c3f683..966bc6093 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyObject.h +++ b/Source/UnrealEnginePython/Private/UObject/UEPyObject.h @@ -24,6 +24,7 @@ PyObject *py_ue_has_property(ue_PyUObject *, PyObject *); PyObject *py_ue_is_rooted(ue_PyUObject *, PyObject *); PyObject *py_ue_add_to_root(ue_PyUObject *, PyObject *); PyObject *py_ue_remove_from_root(ue_PyUObject *, PyObject *); +PyObject *py_ue_auto_root(ue_PyUObject *, PyObject *); PyObject *py_ue_save_config(ue_PyUObject *, PyObject *); diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.cpp b/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.cpp index d17f6facc..f8042fdc3 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.cpp +++ b/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.cpp @@ -72,6 +72,33 @@ PyObject *py_ue_get_player_hud(ue_PyUObject *self, PyObject * args) { return (PyObject *)ret; } +PyObject *py_ue_set_player_hud(ue_PyUObject *self, PyObject * args) { + + ue_py_check(self); + + PyObject *py_hud; + int controller_id = 0; + if (!PyArg_ParseTuple(args, "O|i:set_player_hud", &py_hud, &controller_id)) { + return NULL; + } + + UWorld *world = ue_get_uworld(self); + if (!world) + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); + + AHUD *hud = ue_py_check_type(py_hud); + if (!hud) + return PyErr_Format(PyExc_Exception, "argument is not a AHUD"); + + APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id); + if (!controller) + return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id); + + controller->MyHUD = hud; + + Py_RETURN_NONE; +} + PyObject *py_ue_get_player_pawn(ue_PyUObject *self, PyObject * args) { ue_py_check(self); diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.h b/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.h index 24952c94c..1794008a7 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.h +++ b/Source/UnrealEnginePython/Private/UObject/UEPyPlayer.h @@ -10,4 +10,5 @@ PyObject *py_ue_get_num_spectators(ue_PyUObject *, PyObject *); PyObject *py_ue_get_player_controller(ue_PyUObject *, PyObject *); PyObject *py_ue_get_player_hud(ue_PyUObject *, PyObject *); PyObject *py_ue_get_player_camera_manager(ue_PyUObject *, PyObject *); -PyObject *py_ue_get_player_pawn(ue_PyUObject *, PyObject *); \ No newline at end of file +PyObject *py_ue_get_player_pawn(ue_PyUObject *, PyObject *); +PyObject *py_ue_set_player_hud(ue_PyUObject *, PyObject *); \ No newline at end of file diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyTexture.cpp b/Source/UnrealEnginePython/Private/UObject/UEPyTexture.cpp index 4b45c0e1d..5fef58372 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyTexture.cpp +++ b/Source/UnrealEnginePython/Private/UObject/UEPyTexture.cpp @@ -3,6 +3,18 @@ #include "Runtime/Engine/Public/ImageUtils.h" #include "Runtime/Engine/Classes/Engine/Texture.h" +PyObject *py_ue_texture_update_resource(ue_PyUObject *self, PyObject * args) { + + ue_py_check(self); + + UTexture *texture = ue_py_check_type(self); + if (!texture) + return PyErr_Format(PyExc_Exception, "object is not a Texture"); + + texture->UpdateResource(); + Py_RETURN_NONE; +} + PyObject *py_ue_texture_get_width(ue_PyUObject *self, PyObject * args) { ue_py_check(self); @@ -192,3 +204,25 @@ PyObject *py_unreal_engine_create_transient_texture(PyObject * self, PyObject * return (PyObject *)ret; } +PyObject *py_unreal_engine_create_transient_texture_render_target2d(PyObject * self, PyObject * args) { + int width; + int height; + int format = PF_B8G8R8A8; + PyObject *py_linear = nullptr; + if (!PyArg_ParseTuple(args, "ii|iO:create_transient_texture_render_target2d", &width, &height, &format, &py_linear)) { + return NULL; + } + + UTextureRenderTarget2D *texture = NewObject(GetTransientPackage(), NAME_None, RF_Transient); + if (!texture) + return PyErr_Format(PyExc_Exception, "unable to create texture render target"); + + texture->InitCustomFormat(width, height, (EPixelFormat)format, py_linear && PyObject_IsTrue(py_linear)); + + ue_PyUObject *ret = ue_get_python_wrapper(texture); + if (!ret) + return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); + Py_INCREF(ret); + return (PyObject *)ret; +} + diff --git a/Source/UnrealEnginePython/Private/UObject/UEPyTexture.h b/Source/UnrealEnginePython/Private/UObject/UEPyTexture.h index f10d6f126..4c484a382 100644 --- a/Source/UnrealEnginePython/Private/UObject/UEPyTexture.h +++ b/Source/UnrealEnginePython/Private/UObject/UEPyTexture.h @@ -14,4 +14,7 @@ PyObject *py_ue_texture_get_height(ue_PyUObject *, PyObject *); PyObject *py_unreal_engine_compress_image_array(PyObject *, PyObject *); PyObject *py_unreal_engine_create_checkerboard_texture(PyObject *, PyObject *); -PyObject *py_unreal_engine_create_transient_texture(PyObject *, PyObject *); \ No newline at end of file +PyObject *py_unreal_engine_create_transient_texture(PyObject *, PyObject *); +PyObject *py_unreal_engine_create_transient_texture_render_target2d(PyObject *, PyObject *); + +PyObject *py_ue_texture_update_resource(ue_PyUObject *, PyObject *); \ No newline at end of file diff --git a/Source/UnrealEnginePython/Public/PyActor.h b/Source/UnrealEnginePython/Public/PyActor.h index b8b5d24d0..121e42d04 100644 --- a/Source/UnrealEnginePython/Public/PyActor.h +++ b/Source/UnrealEnginePython/Public/PyActor.h @@ -18,6 +18,7 @@ class APyActor : public AActor ~APyActor(); // Called whenever the Actor is instantiated (before begin play) + virtual void PreInitializeComponents() override; virtual void PostInitializeComponents() override; // Called when the game starts