Yes and no. Doable but not nice :P First, you have to be inside an EditorUtilityWidget child class (or EditorUtilityBlueprint) Then you'll have access to: - GetStreamingLevel -> MakeLevelCurrent - Then SpawnActorFromClass There's also the move function, but it only works on selected actors: - GetStreamingLevel -> MoveSelectedActorsToLevel
@@AlexQuevillonEn In my case I want the spawned enemies to belong to a specific sublevel so when the player moves to the next sublevel the previous enemies get deleted. Then I figured I can just make an array with all spawned enemies (inside my game mode or game instance) and then get the actors and destroy them. That would mean more garbage per session but I guess it won't be too bad unless there are too many destroyed actors. Im not sure what too many means though.
@@3Dcowboyvideos Oh then, you want something that'll work in-game, not in editor. But, in your case, I understand the way you're approaching the problem, but it wouldn't see it that way. What I would do is probably more: - In the BP where you're doing the level loading stuff: - - - Add an EventDispatcher to notify the game that a level is being unloaded. e.g. OnLevelUnloadStarted(String LevelName) - - - And also a variable or something that lets you get the CurrentLevel - In your enemy BP: - - - On BeginPlay, bind to the EventDispatcher - - - On BeginPlay, also save a copy of CurrentLevel to know in which level you are. e.g. AssociatedLevel - - - When the EventDispatcher is called, if the LevelName is the same as the AssociatedLevel, destroy self. And don't worry about it being too much, unless your player changes level every few frames :P
can this be done with blueprints as well?
Yes and no. Doable but not nice :P
First, you have to be inside an EditorUtilityWidget child class (or EditorUtilityBlueprint)
Then you'll have access to:
- GetStreamingLevel -> MakeLevelCurrent
- Then SpawnActorFromClass
There's also the move function, but it only works on selected actors:
- GetStreamingLevel -> MoveSelectedActorsToLevel
@@AlexQuevillonEn In my case I want the spawned enemies to belong to a specific sublevel so when the player moves to the next sublevel the previous enemies get deleted. Then I figured I can just make an array with all spawned enemies (inside my game mode or game instance) and then get the actors and destroy them. That would mean more garbage per session but I guess it won't be too bad unless there are too many destroyed actors. Im not sure what too many means though.
@@3Dcowboyvideos Oh then, you want something that'll work in-game, not in editor.
But, in your case, I understand the way you're approaching the problem, but it wouldn't see it that way.
What I would do is probably more:
- In the BP where you're doing the level loading stuff:
- - - Add an EventDispatcher to notify the game that a level is being unloaded. e.g. OnLevelUnloadStarted(String LevelName)
- - - And also a variable or something that lets you get the CurrentLevel
- In your enemy BP:
- - - On BeginPlay, bind to the EventDispatcher
- - - On BeginPlay, also save a copy of CurrentLevel to know in which level you are. e.g. AssociatedLevel
- - - When the EventDispatcher is called, if the LevelName is the same as the AssociatedLevel, destroy self.
And don't worry about it being too much, unless your player changes level every few frames :P
@@AlexQuevillonEn I might actually try that because the array of spawned enemies don't seem to work so far for some reason Thank you :)