# Accessing properties of a TSubclassOf without having to instantiate an Object

**URL:** <https://forums.unrealengine.com/t/accessing-properties-of-a-tsubclassof-without-having-to-instantiate-an-object/451024>\
**Category:** Editor Scripting\
**Tags:** inventory, tsubclassof, unreal-engine, Scripting, CPP, question\
**Created:** [June 21, 2019, 12:54am UTC](https://forums.unrealengine.com/t/accessing-properties-of-a-tsubclassof-without-having-to-instantiate-an-object/451024 "2019-06-21T00:54:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_4eae6b42](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4eae6b42](https://forums.unrealengine.com/u/anonymous_user_4eae6b42)\
**Post date:** [June 21, 2019, 12:54am UTC](https://forums.unrealengine.com/t/accessing-properties-of-a-tsubclassof-without-having-to-instantiate-an-object/451024/1 "2019-06-21T00:54:16Z")

</div>

Hi guys,

i made an Inventory System in my C++ project where I have a class “Item”. My actual items are then blueprint classes derived from my C++ class “Item”, such that I can modify the name and other factors manually in the respective blueprint. If I gain an item ingme, then this item is added to my inventory, which is a TArray of TSubclassOf of Item. In my inventory widget I now display some random image on the corresponding inventory slot, whenever this slot is occupied by said item.

I then added a UTexture2D\* image to my “Item” class, such that each item has its own display image in the inventory. But since my inventory contains only TSubclassOf objects, I have not instantiated anything, so I am not able to access the item images from my inventory.

Am I somehow able to still access the variables from the blueprints I made? I could of course, whenever I gain an item, instantiate it and add it to the inventory (if I change the inventory type to simply a TArray of Item\*). This would all work fine I tried it. But then I completely unnecessarily have multiple invisible Actors flying around in my scene and have the exact same properties (for example if I cut multiple logs or mine multiple ore etc.). If I later want an option to drop an item, then I want it to be spawned with an actual mesh and position. But right now I only care about their “inner values” and how to access them.

If any of you guys have a solution for this or think my way of doing things is completely retarded, please let me know. Thank you for your help.

---

<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:** [June 21, 2019, 12:58am UTC](https://forums.unrealengine.com/t/accessing-properties-of-a-tsubclassof-without-having-to-instantiate-an-object/451024/2 "2019-06-21T00:58:07Z")

</div>

You talking about class defaults, they are helt in Class Default Object (CDO) and you can access it via UClass:

> **[UClass::GetDefaultObject](https://docs.unrealengine.com/5.1/en-US/API/Runtime/CoreUObject/UObject/UClass/GetDefaultObject/1/)**
>
> Get the default object from the class and cast to a particular type

Note that `TSubclassOf<>` is just template for `UClass*` that limits it to contain specific subclass, in reality you interacting with `UClass*` and you can access that function from it too

Sicne above object use template to you need to use this way as in this example:

```
USomeclass::StaticClass()->GetDefaultObject<USomeclass>();

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4eae6b42](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4eae6b42](https://forums.unrealengine.com/u/anonymous_user_4eae6b42)\
**Post date:** [June 22, 2019, 12:14pm UTC](https://forums.unrealengine.com/t/accessing-properties-of-a-tsubclassof-without-having-to-instantiate-an-object/451024/3 "2019-06-22T12:14:53Z")

</div>

Hi ,

thank you for your answer. I tried a bit around with that and I was only partially able to get what I wanted. But anyways I found a (in my opinion) smoother solution. I made a UStruct FItemData and every time I get an item ingame, the item FItemData(“ItemName”, itemTexture) is added to the inventory. This way I can easly access everything I need in the widget inventory.
