Accessing properties of a TSubclassOf without having to instantiate an Object

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.

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

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>();

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.