# Access Violation On a Member Variable Call

**URL:** <https://forums.unrealengine.com/t/access-violation-on-a-member-variable-call/781500>\
**Category:** C++\
**Tags:** unreal-engine, crash, CPP, question\
**Created:** [March 1, 2023, 8:11pm UTC](https://forums.unrealengine.com/t/access-violation-on-a-member-variable-call/781500 "2023-03-01T20:11:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nonye96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nonye96](https://forums.unrealengine.com/u/Nonye96)\
**Post date:** [March 1, 2023, 8:11pm UTC](https://forums.unrealengine.com/t/access-violation-on-a-member-variable-call/781500/1 "2023-03-01T20:11:38Z")

</div>

Hello, my editor crashes whenever I try to access any variable in a public function on a UActorComponent. I am making the call to that component’s public function inside the tick function of another UActorComponent. This is strange because it is crashing even when I try to simply access a member variable. Below are screenshots of the code, and the crash report:

Code inside tick:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/a/c/3aceeca98996f688d6385128ba50c711de45fcf1.png)

Code in erroring class:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/e/8/2e8a36f489e3279c89854def0521ae27225bbd0b.png)  
Header:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/1/2/812323fa0ce7968fd93034ced0ec271e37d7cba2.png)

Crash Report:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/a/a6aa0d583b9cd437e3247a40abed90fbc3462ae3.png)

---

<div class="post-metadata">

**Author:** ![Ari\_Epic](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ari_epic/32/1225266_2.png) [@Ari\_Epic](https://forums.unrealengine.com/u/Ari_Epic)\
**Post date:** [March 2, 2023, 3:16pm UTC](https://forums.unrealengine.com/t/access-violation-on-a-member-variable-call/781500/2 "2023-03-02T15:16:07Z")

</div>

The crash is happening in the parent function. `hitboxController` is `null`.

This happens because sometimes you can actually call functions on null objects in C++. It sounds weird but kinda makes sense when explained: if the function isn’t virtual then it’s known at compile time what code to run so there’s nothing to crash at until you actually try to access its member variables.

---

<div class="post-metadata">

**Author:** ![Nonye96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nonye96](https://forums.unrealengine.com/u/Nonye96)\
**Post date:** [March 2, 2023, 4:23pm UTC](https://forums.unrealengine.com/t/access-violation-on-a-member-variable-call/781500/3 "2023-03-02T16:23:10Z")

</div>

That was exactly the issue. I was initializing the components inside the constructor. Moving the initializations to the “BeginPlay” method fixed this. Thanks you!

Note:  
it is strange though I was initializing a USkeletalMeshComponent in the same way, but there was no issue calling the methods of that object.
