Python

A shared folder with AI prompts and code snippets

From workspace: Unreal Engine

Team: Main

Total snippets: 20

Unreal Engine

Python

20 snippets

Plugin Build Tool

A user-friendly application designed to streamline the process of building Unreal Engine plugins. With an intuitive interface, it allows users to easily select the Unreal Engine directory, the plugin’s .uplugin file, and the output destination.

#How to build? #This code need to be compiled externally, on any other IDE, like VSCode, need to install python on your computer. #Python: https://www.python.org/downloads/ #VSCode: https://code.visualstudio.com/download #To run the script, run...

Call functions or modify properties of a Blueprint from Python

Shows how to correctly get a blueprint's generated class and how to call a function or modify a property of this blueprint.

import unreal world = unreal.UnrealEditorSubsystem().get_editor_world() # in 5.3 and later, use unreal.get_editor_subsystem(unreal.UnrealEditorSubsystem) # first, get your blueprint asset by any means you want (here from selected asset) bp_asset...

How to reduce the space of Unreal Projects

DBV Unreal Smart Cleaner was born because of the necessity of Unreal Developers who have many Unreal Engine projects in their computer that they don't want to remove from it but that have problems with the disc space.

import argparse import os import shutil import sys #DBVUnrealSmartCleaner was born because of the necessity of Unreal Developers who have many Unreal Engine projects in their computer that they don't want to remove from it but that have problems...

Editor Batch Asset Placing - For overview level + Work with Actor Palette

Place Assets from a folder into the level in the form of a 2D Grid. Each Asset is unique and can be picked with the Actor Palette plugin.

import unreal ################### # Variables to change spacing = 500 folder_path = "/Game/[Path]" # [Path] For exemple Art/MyStaticMeshFolder ################### editor_util = unreal.EditorLevelLibrary() asset_registry =...

Bulk modify start and end frames on selected sequences from the content browser

Editor Utility Widget Python Code - Add fps, startframe and endframe input variables to your Execute Python Script node

import unreal editor_asset_lib = unreal.EditorAssetLibrary() secStart = startframe / fps secEnd = endframe / fps if objref.get_class().get_name() == "LevelSequence": ls = unreal.LevelSequenceEditorBlueprintLibrary() path =...

Non-destructively modify texture Adjustments on textures selected from the Content Browser

import unreal editor_asset_lib = unreal.EditorAssetLibrary() if objref.get_class().get_name() == "Texture2D": path = editor_asset_lib.get_path_name_for_loaded_asset(objref) asset =...

Enable Full Precision UVs on meshes selected from the Content Browser

import unreal editor_asset_lib = unreal.EditorAssetLibrary() if objref.get_class().get_name() == "StaticMesh": path = editor_asset_lib.get_path_name_for_loaded_asset(objref) asset = editor_asset_lib.load_asset(path) MeshSet =...

Enable High Precision Tangent Basis on selected meshes from the Content Browser

import unreal editor_asset_lib = unreal.EditorAssetLibrary() if objref.get_class().get_name() == "StaticMesh": path = editor_asset_lib.get_path_name_for_loaded_asset(objref) asset = editor_asset_lib.load_asset(path) MeshSet =...

Enable Virtual Texture Streaming on textures selected from the Content Browser

import unreal editor_asset_lib = unreal.EditorAssetLibrary() if objref.get_class().get_name() == "Texture2D": path = editor_asset_lib.get_path_name_for_loaded_asset(objref) asset =...

Change Blueprint defaults from python

Sometimes you just have to update some values on multiple blueprints - this should help speed the process up significantly.

def change_blueprint_default_value(blueprint_generated_class, variable_name, new_value): blueprint = unreal.load_object(None, blueprint_generated_class) some_actor_cdo = unreal.get_default_object(blueprint) ...

Move Mouse to Image Location

Accepts a path to an image and moves the mouse to the image location on-screen.

import pyautogui as PAG screenshotIcon = "your_path_to_file" def locateImage(): CurrentScreen = PAG.screenshot() CurrentScreen.save("your_name_to_save.extension") findImage = PAG.locateOnScreen(screenshotIcon, grayscale=False,...

Linear to Gamma conversion in Python

Linear to Gamma conversion and back in Python. It might be useful to someone.

# GAMMA TO LINEAR def convert_ue4_color_gl(rgb_value): color_value = float((rgb_value / 255) ** 2.2) return color_value_gl # LINEAR TO GAMMA def convert_ue4_color_lg(rgb_value): color_value = float((255 * pow(rgb_value, 1 / 2.2))) ...

Create a master material via Python

Python code to create a master material

import unreal AssetMatTools = unreal.AssetToolsHelpers.get_asset_tools() MaterialEditingLibrary = unreal.MaterialEditingLibrary EditorAssetLibrary = unreal.EditorAssetLibrary rc_master_mat = AssetMatTools.create_asset(master_mat_name,...

Create Blueprint Accessible Node in Python

Define UClass UProperty UFunction in python and access in BP

import unreal @unreal.uclass() class MyStaticMeshActor(unreal.StaticMeshActor): value1 = unreal.uproperty(int,meta=dict(Category="MyStaticMeshActor")) value2 = unreal.uproperty(float,meta=dict(Category="MyStaticMeshActor")) value3 =...

Populating StringTables and DataTables with Python (and a little C++ function)

Two example functions on how to import the contents of a CSV file into a StringTable or a DataTable. Most of this is declared in Python, but a small workaround in C++ is needed for ST. Would like to make a full tutorial on this topic in the future.

/*ToolEditorSubsystem is a UEditorSubsystem I have inside an editor module*/ bool UToolEditorSubsystem::ImportStringTableFromCSV(UStringTable* Table, FString FilePath) { Table->Modify(); return...

Exposing Python functions as Blueprint Nodes

Simple snippet on how to declare blueprint nodes in python, showing unreal.uclass and unreal.ufunction decorators.

import unreal @unreal.uclass() class MyPyFunctionLibrary(unreal.BlueprintFunctionLibrary): @unreal.ufunction(static=True, meta=dict(Category="Python")) def hello_world(): unreal.log("Hello world!") ...

Get All AnimNotify of an AnimSequence in Python

Short example of retrieving all the AnimNotify tags in an AnimSequence and printing their names to the unreal log using Python.

import unreal def log_all_notifies(anim): notifies = list( filter( lambda x: x.notify is not None, unreal.AnimationLibrary.get_animation_notify_events(anim), ) ) for notify in notifies: ...

Modify Control-Rig graph in Python

An example showing how to load in a control rig, creating a couple of nodes in it, and connecting them together in Python.

import unreal unreal.load_module('ControlRigDeveloper') # change asset path for your own case rig = unreal.load_object(name = '/Game/ControlRig/Samples/Mannequin_ControlRig', outer = None) # access to the controller to perform...

Control Rig Graph Introspection in Python

Loads in a control rig and loops through all nodes and pins of the graph and prints them out.

import unreal unreal.load_module('ControlRigDeveloper') rig = unreal.load_object(name = '/Game/ControlRig/Samples/Mannequin_ControlRig', outer = None) # access to the graph for introspection # get_model accesses the “Rig Graph” of a Control...

Create a new level sequence and set its framerate in Python

Creates a new level sequence asset in Python and shows an example of modifying it by setting the frame rate of it.

import unreal # Get asset tools asset_tools = unreal.AssetToolsHelpers.get_asset_tools() # Creates a Level Sequence - /Game/Test_LS level_sequence = unreal.AssetTools.create_asset(asset_tools, asset_name = "Test_LS", package_path = "/Game/",...