@@ -8,11 +8,41 @@ PyObject *py_ue_take_widget(ue_PyUObject * self, PyObject * args) {
88
99 ue_py_check (self);
1010
11- UWidget *widget = ue_py_check_type<UWidget>(self);
11+ UWidget *widget = ue_py_check_type<UWidget>(self);
1212 if (!widget)
1313 return PyErr_Format (PyExc_Exception, " uobject is not a UWidget" );
1414
1515 ue_PySWidget *s_widget = ue_py_get_swidget (widget->TakeWidget ());
1616
17- return (PyObject *)s_widget;
17+ return (PyObject *)s_widget;
18+ }
19+
20+ PyObject *py_ue_create_widget (ue_PyUObject * self, PyObject * args) {
21+
22+ ue_py_check (self);
23+
24+ PyObject *py_class;
25+ if (!PyArg_ParseTuple (args, " O" , &py_class))
26+ return nullptr ;
27+
28+ APlayerController *player = ue_py_check_type<APlayerController>(self);
29+ if (!player)
30+ return PyErr_Format (PyExc_Exception, " uobject is not a APlayerController" );
31+
32+ UClass *u_class = ue_py_check_type<UClass>(py_class);
33+ if (!u_class)
34+ return PyErr_Format (PyExc_Exception, " argument is not a UClass" );
35+
36+ if (!u_class->IsChildOf <UUserWidget>())
37+ return PyErr_Format (PyExc_Exception, " argument is not a child of UUserWidget" );
38+
39+ UUserWidget *widget = CreateWidget<UUserWidget>(player, u_class);
40+ if (!widget)
41+ return PyErr_Format (PyExc_Exception, " unable to create new widget" );
42+
43+ ue_PyUObject *ret = ue_get_python_wrapper (widget);
44+ if (!ret)
45+ return PyErr_Format (PyExc_Exception, " PyUObject is in invalid state" );
46+ Py_INCREF (ret);
47+ return (PyObject *)ret;
1848}
0 commit comments