Realize this challenge with AActor::GetDebugName()

I hope I don’t land this question in the wrong section here, I just migrated from Udemy, so please bear with me :slight_smile:

Doing the challenge myself, I thought it would be a great idea to use GetDebugName instead of GetName() since I looked it up in the UE documentation and the description seemed quite fitting:
" Retrieves actor’s name used for logging, or string “NULL” if Actor is null ".

However, I can’t seem to make it work. I know it wants an AActor as a parameter, so that would be
GetDebugName( GetOwner ) no ? and since it returns a FString anyways I wouldn’t have to transform it. However, this line does not work:

UE_LOG(LogTemp, Error, TEXT("%s"), *GetDebugName(GetOwner() ));

The error is:
F:\Unreal_Projects\Building_Escape02\Source\Building_Escape02\OpenDoor.cpp(29) : error C3861: ‘GetDebugName’: identifier not found

i did: #include “GameFramework/Actor.h”

It’s a a static member function so you would call it like so

UE_LOG(LogTemp, Error, TEXT("%s"), *AActor::GetDebugName(GetOwner()));
1 Like

Thank you very much, and congrats on your anniversary of joining this community :smiley:
Of course you solved my problem, but I was wondering since only the scope is what I was missing, when exactly do I have to add that to functions?

I’m sure I haven’t fully understood the static keyword. Other functions are member functions as well no?
Thank you.

When it’s marked as static.

Not surprising as it means at least 3 different things.

  1. static at namespace scope means that it has static storage duration and internal linkage
    static void Foo()
    {
        //code ...
    }
    static int Bar = 0;
    
  2. static at block scope means that it has static storage duration and is initialised once.
    void Foo()
    {
       static int value = 10; // happens *once* the first time Foo() is called
    }
    
  3. static for class members means it’s not bound to any particular instance.
    class AActor
    {
        static FString GetDebugName(AActor*);
    };
    
  4. Then you also have things like static_assert and static_cast which is a compile time assert and cast respectively.

info on storage duration and linkage


That third one is the meaning here. So whilst it’s part of the class it’s not tied to any instance of the class.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms