How to use ALevelScriptActor

Hello,

I want to do as much logic as possible in C++, up to best practices. Is it best practice to make level-specific subclasses of ALevelScriptActor, e.g. one for each level?

For instance, many Level Blueprints have some level-specific scripting off the BeginPlay event. I want to move this scripting to C++. Is the best way to subclass ALevelScriptActor, override AActor::BeginPlay, and then reparent the Level Blueprint?

There is another class, ULevelScriptBlueprint, which also seems relevant but I’m not sure if it fits in. I’ve seen 's Tutorial but that seems to be about defining a subclass of ALevelScriptActor which will be used on every level instead of just a specific one.

Thanks

if you manage to create such a class in C++ and it does work in the editor afterwards, i see no reason for it not to be best practise. C++ is faster than BP in 100% of the cases, and that includes BeginPlay()

it’s easy to do following the tutorial I linked :slight_smile:

There no way (at least no stright forward way) to do level specific C++ level scripts as class is configured in UEnigne class instead of level. Editor simply make extra blueprint class for the level based from that class. You might do something by creating custom UEnigne class and invastigate how LevelScriptActorClass varable in there is used

You might try to make some configurable solution with single C++ class which you could configure in custom AWorldSettings if thats possible with the gameplay you doing

You can set the default LevelScriptActor class on UEngine but you can also reparent a single Level Blueprint to a different LevelScriptActor class in the editor.

Yup, but what about reparenting individual level blueprints? Do people usually do that?

Actully you should use Project Settings to set that UEngine varable ;p

I don’t think so, lot of people don’t even know that you can extend level blueprint from C++. But if it works then i guess it’s ok, just check if it works also in packaged shipping build

what about setting a custom ALevelScriptActor for each level so one dont reinvent the wheel for each level we create ?
image