Creating instances of new blueprint classes?

I am working on an inventory system and need a way to do the blueprint equivalent of this.

Say this is the blueprint as if it were in c++

class InventoryItem {
 InventoryType Type;
 Texture Thumbnail;

Then lets say in the blueprint I do like

vector<InventoryItem*> Inventory; // this would be a global var in the blueprint

// Now I want to create a new instance of the other class blueprint
InventoryItem* i1 = new InventoryItem;
InventoryItem* i2 = new InventoryItem;

// Set some information in each class (or struct maybe?)


// Then add them to the list

Can I do this in blueprint?

I think I know what you mean, so here is my answer…

Lets pretend you are going to make items that have some values, they all have a texture, item, weight, etc

  1. Create a blueprint. Lets call it Master_BP
  2. Create some variables in that blueprint. Lets make one called Name of type Name, Weight of type Float, one called Texture of type Texture2D
  3. Compile and save that blueprint
  4. Right click on the Master_BP and choose ‘Create Blueprint based on this’
  5. Now open the new child blueprint you just created and go to the ‘Defaults’ tab, you should see the variables Name, Weight, and Texture, and these can be set to only that type.

So basically this is like setting up a class in C++ and then making objects of that class. Also if you wire up some functionality in the ‘Graph’ of the master BP, then all the children get that functionality.

The problem with that is, if it is derived from say a UObject is how you you create and initialize it in blueprint?
Spawn actor will require a transform etc, does anyone know how to just create an instance of a blueprint class and fill them into a array?

// Now I want to create a new instance of the other class blueprint
InventoryItem* i1 = new InventoryItem;

Specifically that code there. You could make a blueprint struct, then just add an array of structs to the character and handle your inventory like that but you loose functionality of being able to add member functions etc.

Im also very curious how to do this, OP is this what you meant?

What should I be using as a base class when I make my master blueprint, or can I make it without a base class? If I make it with the base as Object I cannot base any blueprint off of it and I cannot make it off of Actor because I need to spawn the actor in the world before I can do anything with it.

I don’t intend on spawning it anywhere. I just need a place to store the inventory information and need it in an array form so I can loop through it and read from it later.

Try using game mode as your base class.

I am making an inventory system currently and I made the base class an actor class.

Then in my character blueprint, I made an array of that base BP and called it inventory. All my objects are now based off that base BP and all go inside my inventory array nicely, and I can read any single piece of information from any of the array elements I need to.

That’s kinda what I am doing right now however I was having problems with figuring out what I do when I pick up an object. I cannot delete the actor because that means its gone and I lose the class in the array when the games garbage collector is called. Right now I am just moving it to 0, 0, 0 and making it invisible (which wasn’t working anyway) and I figured that probably wasn’t the way to do it correctly. What do you do with it when you pick it up?

Basically that is what I am doing, except I am not moving it to 0,0,0.

This is what I did.

In MyCharacter blueprint, I created a variable called MouseInventory, and set it as the type for the base blueprint. Then when I click on an item in the world, I set the MouseInventory to the item I clicked on and I hide that item.

Now my mouse is basically holding the item, and two things can happen.

  1. If I click on an inventory slot in my character inventory, it copies it from the mouse to the inventory slot, and frees up the MouseInventory to pick something else up.

  2. Or when I am holding the item, I could instead click back in the world which will drop the item when I clicked on in the world. What I do here is move the item from the old location to the new location and then turn it’s visibility back on. Giving the illusion that I dropped it there.

I am having an issue though that you may run into if you do it this way. Basically, for some reason, if you have physics turned on for the objects then the Set Actor Location node doesn’t do anything for any child blueprints.

Here is a link to a Post I made about it.

i haven’t got time to check it but pattym did recently a tutorial on hud level interaction dropping blocks in his level.: [Tutorial] HUD to Scene Interaction - Community Content, Tools and Tutorials - Unreal Engine Forums

Maybe his way to do it can help you. (but as i said i have just see the video not the tutorial.)