UE4 - How to spawn actor at current level, when level streaming?

Hi, i use level streaming, and i need spawned pickups, to spawn at current level, not in persistant level, so they can disappear when i leave;

Right now, if i enter an area that loads another level, if a pick up is spawned using “spawnactor” and i move out from that area, everything dissapears, except that pick up wich stays at persistant level, and its kind of weird, but there is no option to choose a level to spawn, or check if that level is available then spawn in that level, so when i leave, all pickups not taken also dissapear.

Please help

1 Like

I have a strange feeling I’ve already answered this one… :slight_smile:

All spawned actors appear in the persistent level, but never fear… When you spawn them, DO set the Owner parameter. That way, when you unload the stream level, because the owner gets destroyed, the system knows to also destroy the spawned actors…

3 Likes

I dont understand the “DO set the owner parameter” how you do that? could you show BP pics please

I also tried to do that once, but it seems like everything spawns into the persistent level and we can’t specify a streaming level / sublevel where we want to spawn an actor.
So as far as I know, there’s no way to do that, unfortunately.

That´s a flaw in Unreal Engine…

It’s by design I’m pretty sure…

Sorry this took so long, if you quote, people will know you’ve updated the thread:

spawn.JPG

2 Likes

I’m finding this helpful for a similar problem I’m having. It explains a lot that all actors spawn in persistent. However, if you are using world composition with a large number of levels how are you supposed to get the world location of the level to then tell the actors where to spawn?

Get stream level and get transform of the return just returns 0, , 0, 0 everytime. So if you want to say load stream level and spawn player there how do you do it?

Anything that you have in the level will have a world location after streaming, right? So if you make sure there’s a player start in each level, once it appears, you can move the player to that location.

Have you tried the solution presented here? https://answers.unrealengine.com/que…med-level.html

I was looking for a fix like this for a while. I have a menu which is set in a different level and when my spawners were spawning, the actors were spawned in the persistance. Entities that had spawned were visible in the menu where I did not want them

I got around this by adding each spawned entity to a array and then when I load into my menu level, I loop through the array on the begin play and set the actors to be hidden. I do the reverse on the end play event.

Not sure if this helps you out specifically but someone might be here looking for something similar!

After some reading in the Sourcecode, I found something that seems interesting.

In the Declaration of the SpawnActor methods, there always is a parameter of the type FActorSpawnParameters.

/**
	 * Spawn Actors with given transform and SpawnParameters
	 * 
	 * @param	Class					Class to Spawn
	 * @param	Transform				World Transform to spawn on
	 * @param	SpawnParameters			Spawn Parameters
	 *
	 * @return	Actor that just spawned
	 */
	AActor* SpawnActor( UClass* Class, FTransform const* Transform, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters());

It has an “OverrideLevel” member variable that is used in the Definition of the methods to override the Level to spawn in.

/* The ULevel to spawn the Actor in, i.e. the Outer of the Actor. If left as NULL the Outer of the Owner is used. If the Owner is NULL the persistent level is used. */
	class	ULevel* OverrideLevel;
ULevel* LevelToSpawnIn = SpawnParameters.OverrideLevel;
	if (LevelToSpawnIn == NULL)
	{
		// Spawn in the same level as the owner if we have one.
		LevelToSpawnIn = (SpawnParameters.Owner != NULL) ? SpawnParameters.Owner->GetLevel() : ToRawPtr(CurrentLevel);
	}

By parsing a changed Object of the FActorSpawnParameters type into the SpawnActor method one should be able to override the spawning Level.

Other things could also be done this way. FActorSpawnParameters for example also includes an override Name and Owner for the Actor.

One could probably create a Blueprint for this but I don’t know how to do that.

If someone tests this I would be happy to know if it works.

2 Likes