Confusing Python stuff

Hey,
I started this week with Unreal and Python which opened up a lot of questions. What I basically want to do is checking my scene, getting all tagged SkeletalMeshActors, add them all to a sequence record track and start recording.
The problem is, that I can’t filter for tags. (this are the default component tags right?)

[FONT=courier new]all_actors = unreal.EditorLevelLibrary.get_all_level_actors()

skeletal_actors = unreal.EditorFilterLibrary.by_class(all_actors, unreal.SkeletalMeshActor)

tagged_actors = unreal.EditorFilterLibrary.by_actor_tag(skeletal_actors, “TestTag”, unreal.EditorScriptingStringMatchType.MATCHES_WILDCARD)

Also if I want to access the sequence recorder properties, it occurs an error that they do not exist (help says they exist^^).

[FONT=courier new]unreal.SequenceRecorderSettings.set_editor_property(sequence_name, ‘RecordedSequence’)

Am I doing something wrong or are some functions not properly adapted to Python?

Best regards

Here is a script that looks for tags on actors. Would that get you started?

retrieves all Actor in levels having the SU.GUID.XXXX tag

level_actors = unreal.EditorLevelLibrary.get_all_level_actors()
guid_actors = {}
for actor in level_actors:
tags = [str(tag) for tag in actor.tags if str(tag).startswith(‘SU.GUID.’)]
if len(tags) > 0:
guid = tags[0][8:]
if not guid in guid_actors:
guid_actors[guid] = ]
guid_actors[guid].append(actor)

Yeah great, I checked everything again and just used the wrong tag section. The tag search thing works now, but do you have a solution for the second problem? Help tells me that on the sequence recorder settings is something like reduce_keys or sequence_length. How do I access them?
I tried things like this:

[FONT=courier new]unreal.SequenceRecorderSettings.set_editor_property(sequence_name, ‘RecordedSequence’)

or

[FONT=courier new]unreal.SequenceRecorderSettings.sequence_name = ‘RecordedSequence’

but both seams to be not the right way (‘SequenceRecorderSettings’ has no attribute ‘recording_delay’)

Also is it possible to start or stop the editor with a script?

Best regards

Hey, it’s hard to tell from those lines of code, but it looks like you’re not calling set_editor_property() on an instance of the SequenceRecorderSettings object.

SequenceRecorderSettings does have editor properties named recording_delay, reduce_keys, and sequence_length, but not sequence_name. Don’t forget to put quotes around the name of the parameter when you call set_editor_property.

For example:

my_settings_object.set_editor_property(“recording_delay”, 5)

or

unreal.SequenceRecorderSettings.set_editor_property(my_settings_object, “recording_delay”, 5)

Hey thank you! It was a little bit confusing that I have to create an object that handles all the information instead of just write it directly to unreal.
Thank you for you support!
Do you know if it is possible to enter/exit playmode in the editor with a python script? And is it possible to get/set variables in blueprints with python?

Hey, glad you got it working.
That’s a pretty important distinction to keep in mind when you’re working in Python. A lot of the time, you’ll be working with instances of the classes in the Unreal API – like say instances of the unreal.Actor class.
I don’t see any way to launch a Play In Editor session in Python. But you can get/set variables on Blueprint Actors in your Level using the get_editor_property() and set_editor_property() functions – as long as those variables are “public”. That is, as long as the variables have the little eye symbol in the Blueprint editor, so that they show up in the Details panel when you select the Actor in your Level. Like, this works for me:


import unreal

all_actors = unreal.EditorLevelLibrary.get_all_level_actors()

for actor in all_actors:
    print actor.get_name()
    if not actor.get_name().find("MyActorClass") == -1:
        print("property:")
        print(actor.get_editor_property("aString"))


Hey there! I actually stumbled upon this thread because I was wondering how to get/set variables on Blueprint actors (thanks a lot for your clear answer, @Ro-Su-!).
However, I think I can also answer this question (…even if I am two years too late:D):

For exiting playmode, I did a little workaround by just calling the console command “Exit”.


import unreal
def enterPlaymode():
    unreal.EditorLevelLibrary.editor_play_simulate()

def exitPlaymode():
    unreal.SystemLibrary.execute_console_command(unreal.EditorLevelLibrary.get_game_world(), "Exit")

Maybe someone will find this useful.

Have you ever tried these two commands in a common python file.
For example, we have a test.py file, and two functions are “enterPlaymode” and “exitPlaymode”, the main function has only two lines,
“enterPlaymode()
exitPlaymode”
And then “py test.py” in the python or cmd in UE4 4.26;
I find the exitPlaymode will not work.
Could you give me some suggestions?