Why cannot I add blueprint classes derived from an UObject class to my TArray?

I was following a tutorial on YT regarding an inventory system. I did the same as the content creator and noticed that I cannot add items in my character blueprint, they all show up on the drop down menu but whenever I select one, it just keeps it at none.

This is the header code for my inventory component that I attach to the player character.

Problem that I described above resides with the Default Items TArray.

This is my BaseItem class, the one from which other items inherit from (my Medkit for example is created from the Medkit class which inherits from BaseItem):

Here is what is shown in the Player Character Blueprint:

c

What I want to do is to select the default items in the blueprint and then test out my inventory system. Everything else is in place and seems fine (i hope it actually is), except this part. Right now whenever I click anything from this drop down menu it shows none in the inventory.

You have to place the actor in the world and try on that instance for it to accept the pointer of another existing actor.

So you’re trying to put in the blueprint classes and not placed instances of them? Then you should use TSubclassOf<UOBject> instead of UObject*.

If your inventory items all share a base C++ class (recommended) then you can also filter them that way, like TSubclassOf<UInventoryItem> (if that’s what you would name your base class).

1 Like

I tried putting both BP classes and instances of the item class in the editor and the same None thing keeps happening. I did as one guy suggested and put the Instanced keyword to my DefaultItems TArray but that also doesn’t seem to fix the problem.

Working with a TSubclassOf would break the above code for adding and removing items from said inventory. I am still confused as to how to hook all of this up in C++, a lot of stuff on YT/Google is people doing it in Blueprints.

Ah sorry, I misunderstood. Yeah you want Instanced then indeed.

So according to your picture in your first post you can already select the base items to put into the Default Items array, right? This looks good and correct.
image

But it’s not working in the game itself? Where does this “None” show up as you mention?

Whenever I click on any of the available options it just resets to None on the default items. I tried the Instanced keyword and it didn’t help.

All in all, to anyone who might struggle with this, I would say to work around what was shown in the YT clip (the one I am referencing is Reub’s Inventory C++ tutorial) and to just make a Pickup Actor and test their inventory by interacting with the items.

Edit: Forgot to thank you Ari for the information you gave me! :slight_smile: