Skip to content

Commit e729cec

Browse files
author
Roberto De Ioris
committed
fixed blueprint component management, add blueprntfunctionlibrary infrastructure
1 parent 967e2db commit e729cec

File tree

5 files changed

+72
-12
lines changed

5 files changed

+72
-12
lines changed

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -701,30 +701,34 @@ PyObject *py_unreal_engine_add_component_to_blueprint(PyObject * self, PyObject
701701
}
702702

703703
USCS_Node *parentNode = nullptr;
704-
if (parentName)
705-
{
706-
FString strParentName = UTF8_TO_TCHAR(parentName);
707-
if (strParentName.IsEmpty())
704+
705+
if (component_class->IsChildOf<USceneComponent>()) {
706+
707+
if (parentName)
708708
{
709-
parentNode = bp->SimpleConstructionScript->GetDefaultSceneRootNode();
709+
FString strParentName = UTF8_TO_TCHAR(parentName);
710+
if (strParentName.IsEmpty())
711+
{
712+
parentNode = bp->SimpleConstructionScript->GetDefaultSceneRootNode();
713+
}
714+
else
715+
{
716+
parentNode = bp->SimpleConstructionScript->FindSCSNode(UTF8_TO_TCHAR(parentName));
717+
}
710718
}
711719
else
712720
{
713-
parentNode = bp->SimpleConstructionScript->FindSCSNode(UTF8_TO_TCHAR(parentName));
721+
parentNode = bp->SimpleConstructionScript->GetDefaultSceneRootNode();
714722
}
715723
}
716-
else
717-
{
718-
parentNode = bp->SimpleConstructionScript->GetDefaultSceneRootNode();
719-
}
720-
721724

722725
if (parentNode) {
723726
parentNode->AddChildNode(node);
724727
}
725728
else {
726729
bp->SimpleConstructionScript->AddNode(node);
727730
}
731+
728732
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
729733

730734
ue_PyUObject *ret = ue_get_python_wrapper(node->ComponentTemplate);
@@ -769,6 +773,35 @@ PyObject *py_unreal_engine_blueprint_add_member_variable(PyObject * self, PyObje
769773
return Py_False;
770774
}
771775

776+
PyObject *py_unreal_engine_blueprint_set_variable_visibility(PyObject * self, PyObject * args) {
777+
778+
PyObject *py_blueprint;
779+
char *name;
780+
PyObject *visibility;
781+
if (!PyArg_ParseTuple(args, "OsO:blueprint_set_variable_visibility", &py_blueprint, &name, &visibility)) {
782+
return NULL;
783+
}
784+
785+
if (!ue_is_pyuobject(py_blueprint)) {
786+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
787+
}
788+
789+
ue_PyUObject *py_obj = (ue_PyUObject *)py_blueprint;
790+
if (!py_obj->ue_object->IsA<UBlueprint>())
791+
return PyErr_Format(PyExc_Exception, "uobject is not a UBlueprint");
792+
UBlueprint *bp = (UBlueprint *)py_obj->ue_object;
793+
794+
bool visible = false;
795+
if (PyObject_IsTrue(visibility)) {
796+
visible = true;
797+
}
798+
799+
FBlueprintEditorUtils::SetBlueprintOnlyEditableFlag(bp, FName(UTF8_TO_TCHAR(name)), visible);
800+
801+
Py_INCREF(Py_None);
802+
return Py_None;
803+
}
804+
772805
PyObject *py_unreal_engine_blueprint_add_new_timeline(PyObject * self, PyObject * args) {
773806

774807
PyObject *py_blueprint;
@@ -963,7 +996,7 @@ PyObject *py_unreal_engine_move_selected_actors_to_level(PyObject *self, PyObjec
963996
ULevel *level = (ULevel *)py_obj_level->ue_object;
964997

965998
GEditor->MoveSelectedActorsToLevel(level);
966-
999+
9671000
Py_INCREF(Py_None);
9681001
return Py_None;
9691002
}

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PyObject *py_unreal_engine_add_component_to_blueprint(PyObject *, PyObject *);
2828

2929
PyObject *py_unreal_engine_blueprint_add_member_variable(PyObject *, PyObject *);
3030
PyObject *py_unreal_engine_blueprint_add_new_timeline(PyObject *, PyObject *);
31+
PyObject *py_unreal_engine_blueprint_set_variable_visibility(PyObject *, PyObject *);
3132

3233
PyObject *py_unreal_engine_editor_play(PyObject *, PyObject *);
3334
PyObject *py_unreal_engine_editor_on_asset_post_import(PyObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ static PyMethodDef unreal_engine_methods[] = {
155155
{ "compile_blueprint", py_unreal_engine_compile_blueprint, METH_VARARGS, "" },
156156
{ "blueprint_add_member_variable", py_unreal_engine_blueprint_add_member_variable, METH_VARARGS, "" },
157157
{ "blueprint_add_new_timeline", py_unreal_engine_blueprint_add_new_timeline, METH_VARARGS, "" },
158+
{ "blueprint_set_variable_visibility", py_unreal_engine_blueprint_set_variable_visibility, METH_VARARGS, "" },
158159
{ "add_component_to_blueprint", py_unreal_engine_add_component_to_blueprint, METH_VARARGS, "" },
159160
{ "create_material_instance", py_unreal_engine_create_material_instance, METH_VARARGS, "" },
160161
{ "message_dialog_open", py_unreal_engine_message_dialog_open, METH_VARARGS, "" },
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "UnrealEnginePythonPrivatePCH.h"
2+
3+
#include "PythonBlueprintFunctionLibrary.h"
4+
5+
void UPythonBlueprintFunctionLibrary::ExecutePythonScript(FString script) {
6+
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");
7+
PythonModule.RunFile(TCHAR_TO_UTF8(*script));
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
4+
#include "PythonBlueprintFunctionLibrary.generated.h"
5+
6+
7+
8+
UCLASS()
9+
class UPythonBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
10+
{
11+
GENERATED_BODY()
12+
13+
public:
14+
UFUNCTION(BlueprintCallable, Category = "Python")
15+
static void ExecutePythonScript(FString script);
16+
};
17+

0 commit comments

Comments
 (0)