Why is that variable declared ‘static’? Try removing that. Also, did you read the Unreal documentation about smart pointers & about Unreal garbage collection? Granted, if the garbage collector got ya you should have died with a much more gentle NULL pointer exception if memory recalls (and you would have died a few ticks later, not instantly…)
The way you’re spawning from a blueprint is nothing like how I’ve done it.
Normally I expose a class type to the editor like so
// List of Character stats belonging to this character
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Config)
TSubclassOf<class UCharacterStats> CharacterStatsClass;
// Stores all the attributes for the character
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = CharacterStats)
Within my .cpp when I am ready to create the object I do this:
Stats = Cast<UCharacterStats>(StaticConstructObject(CharacterStatsClass));
Setting up your pointers as uproperty ensures it will not be garbage collected. Granted, I don’t think that’s your problem. I do think it’s odd to see a static pointer pointing at a UObject. Havent had time to look at Unreal’s Memory management systems. So no idea if that is allowed or not.
edit- Btw, the reason why your crash will appear random is because it all depends on the contents of the pointer you are using. Try looking at the pointer in the debugger. See if you see any trash in the object (you know, like impossible values assigned to a boolean, etc). You’ve no doubt stumbled unto a bug that has undefined results.