# Calling a HUD-function from Character class (read variable access violation)

**URL:** <https://forums.unrealengine.com/t/calling-a-hud-function-from-character-class-read-variable-access-violation/306697>\
**Category:** UI\
**Tags:** Variable, hud, access-violation, unreal-engine, function, question\
**Created:** [February 11, 2015, 8:03pm UTC](https://forums.unrealengine.com/t/calling-a-hud-function-from-character-class-read-variable-access-violation/306697 "2015-02-11T20:03:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pseudocorpus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pseudocorpus/32/453689_2.png) [@Pseudocorpus](https://forums.unrealengine.com/u/Pseudocorpus)\
**Post date:** [February 11, 2015, 8:03pm UTC](https://forums.unrealengine.com/t/calling-a-hud-function-from-character-class-read-variable-access-violation/306697/1 "2015-02-11T20:03:06Z")

</div>

Hey there,

I am trying to access a function inside my HUD-Class from my Character class. Now that works, but the game crashes trying to read a variable of the HUD-Class.

**ASomCharacter.cpp , here the HUD-Function gets called**

```
void ASomCharacter::PrintNotifyMessage(FText Message)
{
	//initiate owned PlayerController and HUD class
	APlayerController* SomPC = (APlayerController*)Controller;

	if (!SomPC && Role >= ROLE_Authority)
		return;

	ASomHUD* SomHUD = (ASomHUD*)(SomPC->GetHUD());

	SomHUD->NotifyMessages_AddMessage(Message);
}

```

**ASomHUD.cpp , here lies the called HUD-Function**

```
void ASomHUD::NotifyMessages_AddMessage(FText Message)
{

	//Substract lifetime from all entries but the first one
	if (NotifyMessages_Life.Num() > 0)
	{
		for (int32 iSubtract = 0; iSubtract < NotifyMessages_Life.Num(); iSubtract++)
		{
			NotifyMessages_Life[iSubtract] -= 150;
		}
	}

	NotifyMessages_Timer = 500;
	NotifyMessages.Add(Message);
	NotifyMessages_Life.Add(300);
}

```

It looks like the crash happens at line “if (NotifyMessages\_Life.Num() \> 0)” with an “access violation” … the “NotifyMessages\_Life”-Array is an array inside the HUD-Class. What am I doing wrong?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Pseudocorpus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pseudocorpus/32/453689_2.png) [@Pseudocorpus](https://forums.unrealengine.com/u/Pseudocorpus)\
**Post date:** [February 13, 2015, 5:42pm UTC](https://forums.unrealengine.com/t/calling-a-hud-function-from-character-class-read-variable-access-violation/306697/2 "2015-02-13T17:42:01Z")

</div>

Resolved. The “NotifyMessages\_Life”-Array was “protected:” inside the HUD-class
