Hi,
I mean how to REALY use the same BP code/file when the level load ?
I could use functions but I still would have to adjust the BP for each new level
thanks
Hi,
I mean how to REALY use the same BP code/file when the level load ?
I could use functions but I still would have to adjust the BP for each new level
thanks
Hi phil123456,
You can’t - functions will be your only option there…
or with a custom class ? would it be C++ or can I create such a class inside a BP ?
You do seem to be able to re-parent the level blueprint - to LevelScriptActor classes. you may be able to create a subclass of the LevelScriptActor and reparent your level blueprint to that somehow:
(Edit: I just tried making a subclass, but when trying to reparent the level blueprint it doesn’t show that class)
What is it you’re trying to do?
avoiding code duplication for my level blueprints
I just copied the BP from one level to another
it’s super tedious and prone to error
also there is no reason in most games to have a different code per level if it’s well designed
True… I often just duplicate levels when I have things like that I want in each one - but it would be nice to have a type of template system - or at least be able to subclass the levelscript…
Hey there @phil123456! So the Level BP system is great for games with smaller amounts of levels or persistent levels, but to use them for lots of repeated functions can be somewhat tedious. I tend to steer people away from using them over your game instance, game state, or game mode for “global” functions/events.
@RecourseDesign already mentioned functions, but what you said about templates got me thinking if the template system saves the LBP with it or not. I don’t believe it does due to it being just a umap, but there is technically a level templating system!
Disclaimer: One or more of these links are unaffiliated with Epic Games. Epic Games is not liable for anything that may occur outside of this Unreal Engine domain. Please exercise your best judgment when following links outside of the forums.
Older Mathew Wadstein video on level templates:
You could put the blueprint in question in it’s own separate level, and then add that as a sub-level to each of the levels that need it.
This seems like something you could easily just add to your GameInstance though.
and why are you using tick to replace actors?
I would suggest adding this type of code in the Game Mode or Game State classes, so you can track actors’ states using event dispatchers, the way you did in the first branch of the sequence node.
I cant ?
templates ??? hmmm
yeah I think some functions or events or what not could only be used in the level blueprint
but the game instance seems more of a legit place
You sure can but this is not the best practice in terms of performance. Event tick will be firing every single frame, while dispatchers listening for the actor being destroyed will work only whenever the actor sends this information to the Game Mode or Game State. That said, when the actor dies or changes the current state, “call” an event dispatcher associated with it, let’s say “On Death Event”. The Game Mode will be listening for all actors in the Begin Play event (Bind to “On Death Event”)
destroying an actor sometimes causes an error (cant remember the console text, but something about a dependency)
once I kept a list like that, problem was gone
I’ll check OnDeathEvent
never understood why there was a game instance, a level BP and a game mode
so complicated
Game Instance persists through the game run
Level BP is level specific blueprint code
Game Mode defines the rules of the game currently being played
Very likely is something like: “but actor___ is pending kill”. Destroy actor must be the last action performed, and if any blueprint still tries to access that actor, just add a “Is Valid” node before the correspondent function.
If you are feeling brave, you could use a Level Subsystem and put all of this code on there. It is C++ only though and you’d have to implement the base class of the actor you’re trying to handle but it’ll have the same lifetime as your level and will be able to be added on a per level basis
any tutorial ?