BeginPlay is called every time a sub-map is made visible

Hi all,

It appears that in 4.17.1 (and maybe earlier? Untested) that BeginPlay gets called on all actors in a ULevel every time it is made visible. I do not know if this happens using normal sub-levels or not, but when using the LoadLevelInstance blueprint node it does.

If you store a reference to the streaming level returned by LoadLevelInstance and toggle it’s visiblity off and then back on again it will call BeginPlay on all actors contained by that level instance. They do not get unloaded/reloaded as their state stays the same, so toggling visibility just calls BeginPlay.

The exact replication case I have is below, the Client Load Menu function is called once via the GameMode’s PostLogin via RPC, and then the Set Visible is called, toggling the sub-level on and then off and then on again (not shown). Each time the streaming instance becomes visible again it calls BeginPlay.

I do not use standard sub-levels (ie: levels added as children of the Persistent Map), and I do not use streaming volumes. This is just a standalone map A creating an instance of standalone map B and changing the visibility of that.

This happens in both the editor and builds. Unreal 4.17.1, Launcher.

I have the same problem. It can be easily avoided with DoOnce node after BeginPlay, but I would like to know if it’s a bug or an intentional behaviour.

I would also like to know the same.

I have this same issue and it seems like it should be considered a bug. Because BeginPlay seems like the standard event to initialize Actors in UE4 it should only be called once while the object’s state persists. Otherwise it could cause serious issues. For example, if you have a instance editable dictionary on one of your actors and on beginplay it copies the keys of the dictionary to an array so that it can randomize their order whilst not repeating. If BeginPlay is called twice the keys will be copied twice to the array, the array will be twice the size it’s supposed to be, and they will no longer be guarenteed to be non-repeating. You shouldn’t have to remember to add a DoOnce node on every BeginPlay in your game.