Skip to content
  • How to start learning Linux
  • Labtech Implementation Stuff
  • Clogged
  • Active Directory DNS Troubleshooting
  • Some Roulette  Strat from Reddit
  • Mystery steel processing and testing
  • Croissants and Rose Lychee Cream
  • Mac and Cheese
  • DFS Replication: Requirements and Configuration
  • Services.msc not opening in Windows 11/10
  • Microsoft AD LDAP (2008): Importing Your Certificate .pfx File into the AD DS Personal Store
  • Powershell How to get all groups that a user is a member of?
  • Home Energy Saving Tips
  • Changing NTFS Security Permissions using PowerShell
  • VALORANT’S 128-TICK SERVERS

Merserver

Its a website

  • Uncategorized
  • IT
  • Unreal Engine
  • GameDev
  • Interesting Stuff
  • Food
  • Web Design
  • Kubernetes
  • Music
  • Linux
  • Toggle search form

In Unreal Engine 4, how do I get the component’s “game object” via C++?

Posted on October 20, 2022 By samadmin

1

To do this in Unreal and C++, you’ll need to set a pointer to the class and then cast to it.

Casting is expensive in terms of overhead so if it’s something you’ll be doing often, it’s best to get it sorted in Begin Play and call the variable in Tick or whenever you want to call it.

In the .h file:

class ACharacter;

In whatever section (public, private or protected) is best:

ACharacter* ComponentOwner = nullptr;

Over in your .cpp

#include "ACharacter.h"

Then in your Begin Play

ComponentOwner = Cast<ACharacter>(GetOwner());

It is good practise to protect your pointers to avoid crashes. While getting the program working, I’d check here at Begin Play as well:

if (!ComponentOwner)
{    
  UE_LOG(LogTemp, Warning, TEXT("No ComponentOwner found!");
}

and then in Tick or whatever function is calling the character:

if (!ComponentOwner)
{ return; }

// Put your code here

OR

Use GetOwner() in the component

GameDev, Unreal Engine

Post navigation

Previous Post: Blueprints vs. C++
Next Post: Scales and emotions

Related Posts

Choosing TCP or UDP: a guide for game developers GameDev
Expert’s guide to unreal engine performance Unreal Engine
The Complete C++ Guide For Unreal Engine Unreal Engine
The DOOM III Network Architecture GameDev
The TRIBES Engine Networking Model
or How to Make the Internet Rock for Multi­player Games
GameDev
VALORANT’S 128-TICK SERVERS GameDev

Copyright © 2025 Merserver.

Powered by PressBook Masonry Dark