Is there any way to inherit some level blueprint functionality to another level?

Consider making a Blueprint Function Library

I am new at Unreal and i have a project in mind i would like to implement. My issue here is that i will have lots of levels with similar behaviour (i mean basically the same blueprint code) and i dont see any way to make a level “inherit” behaviour from another level, also, different from game instances and player controllers, where i create a blueprint that i can reference later, levels cant be “referenced” in other levels (example, if i create a level instance of a level caled “MyLevel”, the object returned is a Kismet Level Streaming, wich i can’t cast to a “MyLevel” object, even thought is defined by a blueprint)

Is there any way i can achieve this kind of implementation, without having to copy blueprint code to every single level i create?

It isn’t an exact solution, but create an Actor BP you can put into each level, called Level Initialiser or something? Have that parent a set class and then create childen for each level and place on in each. Then on the begin play of those actors, do your stuff. You could even call an ‘Init’ function from the BeginPlay of each level blueprint on the instance in that level.

Again, not an exact solution but more of a work-a-round.

What is the real world problem you are trying to solve? Ideally, you should not have any code in your Level Blueprint at all. There are some exceptions, but by the time you work out what they are, you would not be asking questions like this.

For now, imagine there is not such thing as level blueprint. How would you get that functionality in other ways?

I have this same problem.
In my case, I have many levels which can load and unload. Enemies are spawned from randomized “Spawn Points” in each level.

When the player leaves an area, the enemies or NPCs states need to be stored. So when a level is about to be unloaded, first I loop through them and check which actors are inside of that level by line tracing down and checking the landscape they are standing on. I use a filter so that only the landscape can be hit.

If they are standing on a landscape belonging to the level being unloaded, then all of the data about that actor is stored in an array of actors in the gamemode. To be more specific, it is an array of maps which each index in the array of maps also contains an array of actors.

When a level needs to load, it checks some variable, like the in-game Data/Time the level was last loaded and the actor array associated to that level.

If the level was loaded a long time ago, the list of old actors is cleaned and new actors are spawned and the items are also cleaned.

If the level was loaded recently, then it reloads all of the actors/items into the scene in the exact location they were before with the exact same stats.

But because there’s no inheritance solution, I have to copy paste this code into every single level blueprint. And there are a lot. If the code needs to change, I have to copy paste it to all of them again! It’s pretty bad.

So what I just did was I moved all my code into macro/function libraries. So I now call two functions in each Level Blueprint that handles everything above. No more copy pasting. I feel dumb for having done that. Still have to make sure to paste those two functions but that’s fine. The spawning of the actor has to be done in a macro because it is asynchronous, which function libraries don’t handle.