I tried to use UnloadLevel
node in blueprint and call it in my PlayerController
blueprint. For some reason, every actor made statically (by inserting via Editor), gets destroyed. But all actors dynamically created and spawned in that level, via blueprint, do not get destroyed. Why?
Hey Pelangi,
Could you do me a favor and double check that the actors that are not being destroyed are definitely part of the level that is being unloaded? Is it possible that these actors are being spawned in the persistent or other level instead of the level that you are unloading?
Iāll try to give the steps as best as I can to replicate this. The target platform is for smartphones.
- For example, letās say I have 3 levels:
ParentLevel
,ChildLevel1
, andChildLevel2
. -
ParentLevel
is the persistent level. -
ChildLevel1
is a sibling ofChildLevel2
. They both are insideParentLevel
. - Create a simple custom widget, letās say
UMyWidget
. Inside it, just add a simple image, via editor, and implement theOnTouchEnd
event inUMyWidget
blueprint. InsideOnTouchEnd
, unloadChildLevel1
and load streamChildLevel2
. - In level blueprint for
ParentLevel
, I unloadChildLevel2
and load streamChildLevel1
. It is done insideBeginPlay
event. - Inside
ChildLevel1
, I inserted a simple actor, via Editor, which consist of a single static mesh. Letās say it isABox
. - Inside
ABox
blueprint, I implement theOnInputTouchEnd
event. Inside it, I spawn another actor, letās sayABall
. - Inside
ABall
blueprint, I implement theOnInputTouchEnd
event. Inside it, I callCreateWidget
node to createUMyWidget
and then call nodeAddToViewport
, to put it on the screen. - Play the game!
- Click
ABox
then clickABall
then click the image insideUMyWidget
. - Notice that
ABall
is not destoryed.
Thanks for the steps, Iāve found that simply unloading a streamed level with a dynamically spawned actor does not destroy the actor.
I have entered a bug report for this, which you can track here:
Thanks for your report.
Have a great day
The bug report says that it has been resolved, but Iām still having issues with this bug in 4.14 and 4.15. Is it not fixed yet?
The bug is marked as By Design. The reason is that spawned actors are in the āpersistentā level and will not automatically go away when levels are streamed out.
Thatās dev code for they are not going to bother fixing it, I assume, as no one would actually design the system that way.
I look the bug marked as by design, so how to I design it can let the actor destroy when level stream unload. the actor spawn in child level bp, so i want when the child level unload , the actor instance also can destroy. how to deign ?
for me this is a problemā¦i have been using get all actors of class and then destroy actorā¦for each actor class that is in the sceneā¦i have been getting other problems also when trying to unload streaming levels while using ai behaviour kitā¦even though i get all actors of class and delete themā¦over time performance drops because when deleting ai with collision spheres for meleā¦the actors are deleted but not the collision spheresā¦and even though i get all actors of class and delete the collision spheresā¦the peerfomrance still drops over time after streaming levels back and forthā¦maybe the actor is still referencedā¦but ā ā ā ā ā¦if it would just delete actors that exist on the level that would be nice
Spawning an actor from within the sublevel blueprint is not sufficient to bind the actor lifetime to that of the level, what you have to do is assign an owner to the new actor (in blueprint editor expand the spawn node to reveal the Owner pin). When you donāt specify an owner explicitly, the persistent level is used by default. On the other hand, if you plug any actor owned by that sublevel (or the sublevel itself) into the owner pin, the spawned actor should be destroyed correctly when the level is unloaded. You can for instance place an empty actor in the sublevel and pass it as owner to the spawn node (this can be easily wrapped inside a dedicated blueprint).
Hope it helps
It would be great if someone could expand on how to āpass it as the owner to the spawn nodeā ā I can seen the owner node in the SpawnActor but how to get a reference to an actor that is in the level? in the level blueprint?
I realize itās been a while since this question has been asked, but Iāll show you my findings regardless.
Iāve been working on a game that uses smaller levels which are streamed in as the player gets close. In these test levels, I wanted to be able to spawn actors in dynamically, and have them despawn when the player gets too far. I made a blueprint which line traces directly downward, seeking a solid object. When this object (the landscape) was hit, the game would spawn in the barrels I made, but upon unloading the level, the barrels would persistāsuspended in the void which the absent level created.
Using the hit result from the line trace, you can take the actor which was hit and set it as the barrelās āownerā. Exactly like Mercanti said, it seems to have sent the barrels to the proper level, and they now despawn properly along with the level.
Still broken in 4.27.
Actors are 100% children of a streaming level.
Some emitters persist after unload.
Any actor modified (movement/resize/etc) persists after unload.
Nope.
You havenāt assigned the owner to them: if you donāt do this, Ue4 will spawn in the persistentā¦