Crash when SetAnimation() is called

Hi,
I Updated my project from ue 4.17 to 4.22.1 everything worked fine in the editors viewport when playing the game, but if i start the game in standalone mode or package it it will crash every time after ca 2min, with a access violation error which is caused by SetAnimation(). I use this method to switch between two UAnimationAssets, which works fine but after two minutes it crashs.

link text

Hey,

Looks like a garbage collector related problem.

Could you show the “weaponVisible” variable declaration ?
Same for the “weaponConfig”, “emptyAnimation” and “shotAnimation”

Hi,
Seems unlikely the the garabage collector removes it, wouldn’t the animation asset be NULL then, also the animations are used all the time.

Photos are attached.
Thanks for the help in advance.

Sorry, i meant the header part ( but you can just confirm that they all are UPROPERTY )

You said access violation, but could you check what variable is null causing thz crash with a debugger ?

I would say it’s the “weaponVisible” but as you set it as root component it should’nt change.

Ok thanks for the help i marked both of my UAnimationAssets as UPROPERTY() and now it works. So it really was the garabage collector. But why did it remove those assets in 4.22 and not in the Engine version 4.17, also shouldn’t the if (asset != NULL) part return true then?

But still thanks a lot.

That’s how c++ work, the pointer is just an adresse ( and here it has not null ) but when you actually try to reach the object, if it has been replaced by something else or destroy, it throw access violation. Having the uproperty allow 2things, the object won’t be garbaged colected automatically, and if the object is destroyed, the property will be set to null.

You also have the “IsValid” macro to check it the pointer is valid before accessing it