# Issue with UObject memory access violation

**URL:** <https://forums.unrealengine.com/t/issue-with-uobject-memory-access-violation/2031215>\
**Category:** C++\
**Tags:** c-c, c-class-wizard, c-and-bluepri, c-custommeshcomponen, c-and-blueprint, c-error, c-class, c-custom-shape, c-programming, c-cone-shape, unreal-engine, crash, CPP, question\
**Created:** [September 21, 2024, 1:35pm UTC](https://forums.unrealengine.com/t/issue-with-uobject-memory-access-violation/2031215 "2024-09-21T13:35:15Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [September 21, 2024, 3:12pm UTC](https://forums.unrealengine.com/t/issue-with-uobject-memory-access-violation/2031215/3 "2024-09-21T15:12:29Z")

</div>

@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](https://dev.epicgames.com/documentation/en-us/unreal-engine/objects-in-unreal-engine) - _“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](https://dev.epicgames.com/documentation/en-us/unreal-engine/reflection-system-in-unreal-engine) and especially about [CDO (Class Default Object)](https://forums.unrealengine.com/t/what-is-cdo/310820).  
Also, this one might be useful: [c++ - Unreal Engine 4. Different ways to instantiate the object - Stack Overflow](https://stackoverflow.com/questions/60021804/unreal-engine-4-different-ways-to-instantiate-the-object)

---

_[View the full topic](https://forums.unrealengine.com/t/issue-with-uobject-memory-access-violation/2031215)._
