# Unreal Property System? some questions

**URL:** <https://forums.unrealengine.com/t/unreal-property-system-some-questions/348258>\
**Category:** Rendering\
**Tags:** reflection, uht, unreal-engine, question\
**Created:** [February 22, 2016, 1:00pm UTC](https://forums.unrealengine.com/t/unreal-property-system-some-questions/348258 "2016-02-22T13:00:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wilq83](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wilq83](https://forums.unrealengine.com/u/Wilq83)\
**Post date:** [February 22, 2016, 1:00pm UTC](https://forums.unrealengine.com/t/unreal-property-system-some-questions/348258/1 "2016-02-22T13:00:57Z")

</div>

Hi. I would like to get some deeper understanding for Unreal Property System.  
During reading article

> **[Unreal Property System (Reflection)](https://www.unrealengine.com/en-US/blog/unreal-property-system-reflection)**
>
> Reflection is the ability of a program to examine itself at runtime. This is hugely useful and is a foundational technology of the Unreal engine, powering many systems such as detail panels in the editor, serialization, garbage collection, network...

i suddenly encountered this moment which i tottaly dont understand

“You can get the UClass or UScriptStruct for a reflected C++ type by writing UTypeName::StaticClass() or FTypeName::StaticStruct(), and you can get the type for a UObject instance using Instance-\>GetClass() (it’s not possible to get the type of a struct instance since there is no common base class or required storage for structs).”

Can someone give me some example ?  
Beacuse from what i understood before any created class i should put UCLASS() macro but what about above mentioned situation?  
Thanks

---

<div class="post-metadata">

**Author:** ![Kiruse](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kiruse](https://forums.unrealengine.com/u/Kiruse)\
**Post date:** [February 27, 2016, 11:49pm UTC](https://forums.unrealengine.com/t/unreal-property-system-some-questions/348258/2 "2016-02-27T23:49:38Z")

</div>

Randomly stumbled upon this question while browsing the wiki for more information on the property system.

The quote simply means that it’s possible to call `UObject::GetClass()` on any given `UObject` instance, but not on any `F` instance because there simply is no class from which all structs derive, unlike the `UObject` class for all objects.

Example:

```
// Assigned somewhere in your code
AActor MyActor;
// Get a pointer to the AMyActorClass UClass instance at runtime.
UClass *MyActorClass = AMyActorClass::StaticClass();

// For the sake of this example, the following code SHOULD work (not sure right now,
// haven't tested), even though there is a method UObject::IsA() which does the same.

if( UClass::FindCommonBase(MyActor->GetClass(), MyActorClass) == MyActorClass ) {
    // Print a debug message for 10 seconds on screen. For more info, google the function.
    GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Yellow,
        // This is just the text we want to display.
        FString(TEXT("My actor is an instance of AMyActorClass"))
    );
}

// This will not work because the `GetClass()` method is defined nowhere within the Unreal Engine:
FColor::Yellow->GetClass();

```

The above code should attempt to find the first common base between the two given classes, namely the class of the given `AActor` instance and a custom class `AMyActorClass`. If the provided actor indeed is an instance of `AMyActorClass` the check should return true and print an onscreen message. If it is not, nothing should happen.

However, the last line will result in an error because the symbol `GetClass` is undefined. It is neither defined in `FColor` nor in any of its parent structs - in fact, `FColor` does not derive any struct at all. I found a nice little complementary article on garbage collection [here](https://wiki.unrealengine.com/Garbage_Collection_Overview). It also explains the difference between structs and objects in UE4.

I’m by far not proficient with the Unreal Property System and frankly I’m a bit confused about the `FTypeName::StaticClass` part - usually structs or unreflected classes are prefixed with _F_ meaning they are more or less out of scope of the property system. Thus `FTypeName::StaticClass`, as for my understanding, usually is an undefined symbol as well.

Once you have access to a `UClass`, you can use `TFieldIterator It(MyClass)` to iterate over the reflected fields of your class. This would be useful for custom serialization where you want all reflected properties to be somehow saved to a file, for example.

---

<div class="post-metadata">

**Author:** ![Wilq83](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wilq83](https://forums.unrealengine.com/u/Wilq83)\
**Post date:** [March 5, 2016, 12:36am UTC](https://forums.unrealengine.com/t/unreal-property-system-some-questions/348258/3 "2016-03-05T00:36:56Z")

</div>

Hi Newest…  
Thanks for effor answering this question. But Could comment every line in your code comment. I mean for example  
UClass \*MyActorClass = AMyActorClass::StaticClass();  
What does it mean? Why you create pointer?.. What is StaticClass() function?

---

<div class="post-metadata">

**Author:** ![Kiruse](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kiruse](https://forums.unrealengine.com/u/Kiruse)\
**Post date:** [March 11, 2016, 11:29am UTC](https://forums.unrealengine.com/t/unreal-property-system-some-questions/348258/4 "2016-03-11T11:29:45Z")

</div>

There are several reasons, but the most evident one is simply because that’s the method’s signature. `UObject::StaticClass()` returns a pointer to a `UClass` object. We are not creating the pointer, we are receiving a pointer.

That in turn, however, has to do with the inner workings of the Unreal Engine. In order for UE4 to properly manage memory for us we avoid directly interacting with memory. Thus if we were to create a new instance of the `UClass` class and copy the values that UE4 has stored internally over to that new class we’d have a potential memory leak since UE4 has no way of knowing what you’re doing with that instance afterwards. For example you could store it elsewhere and forget to free it. Do that ten thousand times and you have significant memory loss.

The `UObject::StaticClass()` method is defined in the `UObject` class and inherited from every class with the prefix U or A. The class simply returns a pointer to the UClass instance which represents the class on which the statc method was invoked on at runtime. In this example, `AMyActorClass::StaticClass()` returns a pointer to a `UClass` which represents and stores information on the `AMyActorClass` at runtime.

Hope this helps?
