Issue with UObject memory access violation

@SupTwo

This is a common mistake: you misunderstood what the constructor does in Unreal Engine, it’s not the same as regular C++ constructor.

See documentation about UObject Creation - “UObjects should only be constructed using NewObject at runtime, or CreateDefaultSubobject for constructors.” - In your code you’re using NewObject inside of AGameTest::AGameTest constructor which is against said rule.

I presume, you wanted to fire some logic when the AGameTest actor spawns (when the Game starts). In this case you should probably move everything from AGameTest::AGameTest to AGameTest::BeginPlay.

This code is simply not going to work the way you expect. Read about Unreal Engine Reflection System and especially about CDO (Class Default Object).
Also, this one might be useful: c++ - Unreal Engine 4. Different ways to instantiate the object - Stack Overflow

1 Like