World Settings: Begin Play called when streaming a level

Hi everyone,

When I load a streamed level, the AWorldSettings::BeginPlay method seems to be called. This is very annoying when using it to create singleton-like objects to manage things for a specific maps with custom settings for each map.

I don’t know if this behavior is expected or not, I thinks there is an engine bug using world settings when level is loaded where it should not. If this is expected, it is very weird as world settings can be accessed in editor only for persistent level.

Hopping it helps.

Hey HellSuffering,

I’ve tested this by creating my own World Settings class and logging a message on BeginPlay() and then streaming in a level, but I’m not seeing the same results.

Would you mind providing me with a detailed list of repro steps I could use to reproduce the issue on my end?

Thanks

Hey Sean,

It will be difficult for me to give you a detailed list of repro step, I use specific classes but I just create a UObject in World Settings Begin Play that I set in my game singleton class.

If it can help you I load my level with UGameplayStatics::LoadStreamLevel, creating a LatentActionInfo with an arbitrary UUID, all of this in C++ only.

I can try to log a message too in the begin play to see what happens

I tried to log a message on screen in the World Settings Begin Play method, and I get the log.

This is how load levels if it can help:

	// Here is where I call my loading / unloading method
        for (int32 i = 0; i < m_StreamingOptions.Num(); i++)
	{
		StreamLevel(m_StreamingOptions[i], i);
	}

// Here is my method to load / unlaod sublevel
void UMETA_LevelStreamingComponent::StreamLevel(const FMETA_StreamingOptions& _StreamingOptions, int32 _UUID)
{
	FLatentActionInfo latentActionInfo;
	latentActionInfo.UUID = _UUID;

	if (_StreamingOptions.Load)
	{
		// Load level
		UGameplayStatics::LoadStreamLevel(GetWorld(), _StreamingOptions.LevelName, true, m_BlockOnLoad, latentActionInfo);
	}
	else
	{
		// Unload level
		UGameplayStatics::UnloadStreamLevel(GetWorld(), _StreamingOptions.LevelName, latentActionInfo);
	}
}

Sorry for the delay.

At this time, we do not believe that this is a bug with the engine.

After further testing, I was able to reproduce the issue; however, I believe that this is working as intended. Begin Play is called each time a level is loaded or has “begun play” and I would expect that it would be the same for World Settings.

I’d recommend looking into alternatives if this functionality is causing issues with your current setup.

Have a great day

Ok, so it is expected. I already fixed it (just checking if my object instance already exists before creating it and set it).

I not saw anything on this in the do, so I was not sure if it was intended or just a bugc, may be it should be in the doc.

Thanks for your answer,
Have a great day too :wink: