# How do you access a class member of another class from a separate class

**URL:** <https://forums.unrealengine.com/t/how-do-you-access-a-class-member-of-another-class-from-a-separate-class/488974>\
**Category:** C++\
**Tags:** game-mode, unreal-engine, CPP, question\
**Created:** [September 19, 2021, 3:47pm UTC](https://forums.unrealengine.com/t/how-do-you-access-a-class-member-of-another-class-from-a-separate-class/488974 "2021-09-19T15:47:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zero3021](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zero3021](https://forums.unrealengine.com/u/Zero3021)\
**Post date:** [September 19, 2021, 3:47pm UTC](https://forums.unrealengine.com/t/how-do-you-access-a-class-member-of-another-class-from-a-separate-class/488974/1 "2021-09-19T15:47:56Z")

</div>

Hi so im currently trying to access a member of a game mode class from a Character class and ive been having problems getting it to work, i have looked around but i haven’t much that i understand i tryed to cast my game mode class to my player class but i haven’t been able to get it to work i also don’t want to get the current levels game mode just one specific one, could some shed some more light on how to use cast like do i have to #include a specific module to use it or does someone know a simpler way to access the variables of another class

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [September 21, 2021, 4:11pm UTC](https://forums.unrealengine.com/t/how-do-you-access-a-class-member-of-another-class-from-a-separate-class/488974/2 "2021-09-21T16:11:58Z")

</div>

Hello! Unreal’s CAST is very similar to C++ cast. It is just make a child class pointer from parent class pointer, so after casting you can use child functionality.

“i tryed to cast my game mode class to my player class” - you cant do that, because game mode class is not player class at all!

---

<div class="post-metadata">

**Author:** ![KuroPhoenix7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KuroPhoenix7](https://forums.unrealengine.com/u/KuroPhoenix7)\
**Post date:** [September 22, 2021, 11:31am UTC](https://forums.unrealengine.com/t/how-do-you-access-a-class-member-of-another-class-from-a-separate-class/488974/3 "2021-09-22T11:31:12Z")

</div>

if(AMyGameMode\* myGameMode = Cast(GetWorld()-\>GetAuthGameMode()))  
{  
myGameMode-\>myMember = 0;  
}  
you can get the gamemode like this
