# How to cast to UClass?

**URL:** <https://forums.unrealengine.com/t/how-to-cast-to-uclass/464343>\
**Category:** Community & Industry Discussion\
**Tags:** casting, UClass, unreal-engine, template, question\
**Created:** [April 27, 2020, 4:44pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-uclass/464343 "2020-04-27T16:44:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_d9228c26](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d9228c26](https://forums.unrealengine.com/u/anonymous_user_d9228c26)\
**Post date:** [April 27, 2020, 4:44pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-uclass/464343/1 "2020-04-27T16:44:42Z")

</div>

Example below is not working, but it illustrates what I want to get  
I know that templates are not supported for UClass, but I’m searching for some version of cast which accepts uclass as a function parameter or any other workaround

```
class Foo {
    FString Name;
}

TSubClass<Foo> Bar;
TArray<Foo> arr;

FString Name = Cast<Bar.Get()>( arr[i] ).Name;

```

---

<div class="post-metadata">

**Author:** ![timtimmy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@timtimmy](https://forums.unrealengine.com/u/timtimmy)\
**Post date:** [April 28, 2020, 12:53am UTC](https://forums.unrealengine.com/t/how-to-cast-to-uclass/464343/2 "2020-04-28T00:53:54Z")

</div>

For this to work, wouldn’t class Foo need to look like this?

```
UCLASS()
class Foo {
   GENERATED_BODY()

   FString Name;
}
```

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [April 29, 2020, 6:49pm UTC](https://forums.unrealengine.com/t/how-to-cast-to-uclass/464343/3 "2020-04-29T18:49:04Z")

</div>

Thats not possible, C++ types only exist in compile time and it’s only used to construct machine code, they are not dynamic in anyway. Same goes with templates.

Also i don’t really understand why you want to do this looking on the code, you expect type Foo to have a property Name… why you casting it then?

You might also look in to interfaces which solves lot of class relation problems

> **[Interfaces](https://docs.unrealengine.com/5.1/en-US/interfaces-in-unreal-engine/)**
>
> Reference to creating and implementing interfaces.
