TO start, go into the unreal plugins, look for python. Turn on Python Editor Script Plugin. Go into settings and look for python, make sure developer mode is turned on (you will have to restart unreal).
Go into your unreal project, inside intermediate>PythonStub, you'll find unreal.py file
Make a new visual studio project, copy and paste this unreal.py file into your new project.Make a new python file named logger.py. Import the unreal file and right out a log statement. This will help so that visual studio will autofill the unreal functions.
import unreal
unreal.log("Tech Art Rocks!")
Save this file. Then go to your unreal project. At the bottom right you should see a place to write commands. You can change this to python instead.
You can also log warnings and errors.
unreal.log_warning('this is a warning')
unreal.log_error('this is error')
Press up on the keyboard while in the text box to go back to a previous command.
If you want to have scripts that automatically load on startup, go to project settings,
Restart Unreal to see the script automatically run when it starts up again.If you want to add more paths to the default PYTHON_PATH in your unreal project, you can also do that in the project settings using the 'additional paths' parameter.
This will need to restart unreal again to apply the settings.
Want to install other packages to your python like numpy? Go to this file location
C:\Program Files\Epic Games\UE_5.4\Engine\Binaries\ThirdParty\Python3\Win64
Open up a command prompt and change to this directory.
We're going to be using pip to install numpy
This should have installed numpy and you can use it to perform matrix multiplication.
In unreal python, you have UObjects and they've got properties you can get/set them. You can see the documentation here.
Here's a script that prints the name, path name, full name, and class type of selected objects in editor:
import unreal
#decorator
@unreal.uclass()
class EditorUtils(unreal.GlobalEditorUtilityBase):
pass
selectedAssets = EditorUtils().get_selected_assets()
for asset in selectedAssets:
unreal.log(asset.get_full_name())
unreal.log(asset.get_fname())
unreal.log(asset.get_path_name())
unreal.log(asset.get_class())
unreal.log(type(asset))
unreal.log('#####################')
No comments:
Post a Comment