Need help with weird VariantManager crash

I need help with an impossible crash that happens with Variant Managers.

Summary:
On Event BeginPlay, I load a Variant Manager and activate some Variant. All works fine the first time I load a level, but the second time I load the level, it crashes. This happens both in a Packaged Project and in Editor ‘Standalone Game’.

So the sequence is:

  1. Begin Play is successful the first time. VariantManagers load as they should.
  2. Navigate to another level, all is good.
  3. Go back to the first level, instant crash.

However:

  1. If I load the Variant Manager but don’t apply a Variant, no crash.
  2. If I load the Variant Manager, delay 2secs and then apply a Variant, no crash
  3. If I run in PIE, no crash

What can possibly be happening here? Is there an invalid reference to VariantManager that fails when accessed on second-level-load? How can I possibly investigate this further? I would make a bug report, but it’s so hard to replicate this issue..

Crash reports different things at different times, but usually related to an array, when accessing
UnrealEditor_VariantManagerContent:

Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\Array.h] [Line: 758] Array index out of bounds: -2146525327 into an array of size 0
Assertion failed: Index >= 0 [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Public\UObject\UObjectArray.h] [Line: 868] 
Assertion failed: this [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Class.cpp] [Line: 2432]

Apologies, won’t be able to help but just commenting that I’ve encountered possibly a similar issue?

Going from one level to the other and back, the variant is set fine the first few times then fails with an assert, out of bounds array like you’ve shown.

Seems like a binding goes out of whack and it fails to resolve?

Tried numerous things, thought it may be due to loading or something similar so had added a delay but get the same issue.

This happens to me in PIE however, as you’ve noted you don’t get this in PIE.

Hi there,

Never really got to the heart of the issue, but found a ‘workaround’. Haven’t seen crashes since.

The thing to do is to collect garbage before opening a new level as well as before addressing the VariantManager, something like this:

Hope that helps!

W

This seems like quite the hacky workaround, but if it works validates a bit of what I thought the problem could be :grimacing:

Thanks for the reply, I’ll try the same and see how it goes

Probably would be worth having a singleton or use the asset manager to load the variants and keep them around maybe, to save on having to load them and GC after.

Let me know if you have any new insights!