Data from actors

I think you are right and I was confused about a few things. I was just not sure how to pull data off of a class and sort of still am. It is possible, though.

My plan is to have items in my games never actually be spawned and just have their data stored in classes since it will be menu driven. With a reference to that actor class you can get whatever you need to know about it. I am just having trouble with which functions to use to get the data. When I try to get the data, the function used wants to be of that specific class and cannot be used by other classes. I am thinking that maybe I have to make the actor class move the data into a temporary variable where my inventory is stored so that I may get it from there. I am sure that there is an example of the correct method on the internet somewhere.

I apologize that my being such a novice has taken up some of your time. I have learned from our conversation, though. It also gives me a great deal of hope and comfort to know that there is help available on the forums if needed.

I think I finally saw what I needed. I was watching a person on youtube and they created a blueprint interface and a function within it to return a name. I had seen this done before. What I had not seen is when he added that interface to the actor in question, he was able to customize it in whatever way he wanted. So I simply made a function that returns the name variable of the actor.

The Parent blueprint can contain the variables and functions. Master Item has variable Name and Function PickUp. Any blueprint created from Master Item (right-click, Create based on) becomes a Child and has automatic access to the Name variable and the PickUp function. You don’t have to define it again in the Child blueprint.

Any variables or functions of the Child blueprint cannot be accessed by the Parent blueprint. So the Eat function on the Child will not be able to be referenced off of the Parent blueprint.

You can Call To the Parent blueprint to reference any and all functions of the Parent and its Child(ren). So a Level blueprint that calls to Master Item has access to the Eat function and the Name variable.

At least that’s my understanding of how the system works.

Exactly. You just need to make a few structs for each item type (ie, armorStruct, weaponStruct, potionStruct etc), and then add all those as variables to your parent class. Then make an Enum for “ItemType” and also make that a var.

Then when you make a BP based on it, you simply only edit the relevant properties and always define the Enum Item Type to be either Armor, Weapons, etc.

In that way you can access all the data and there is no casting requirement. You would simply implement a few branches using the itemType Enum. You could either do it all in one place in a separate BP or actually have these item BPs contain their own logic. Additionally you could choose what gets done in the parent construction script and what gets done in the children on an individual basis so it would be a very open system.

Ok, now I am slightly confused on that piece right there. Does that mean that I could reference the DefenseValue on the armorStruct of the LeatherGloves blueprint, assuming the LeatherGloves was a child of Master Item and armorStruct was set as a variable in Master Item?

…or am I reading that wrong?

So let’s say that:

armorStruct has Defense, Weight and PositionOnBody as its Structure.
LeatherGloves (child blueprint of Master Item) would use the ItemType (Enum variable defined in Master Item blueprint) of armorStruct (Struct variable defined in Master Item blueprint) and be able to set the Defense and PositionOnBody?

How would the Level blueprint reference the Defense of LeatherGloves for seeing how tough they are for bashing in a wooden fence?

Yes you can still access it. You just have to select “show inherited variables” in the view icon drop down of the child BP.

I am putting together a small mini-version of this then I can hopefully show you images of the way its set up.

Ok here is just a super quick example of building a system like this with a single Parent BP class.

First, here is the folder structure I use for this test:

86d0fa376f860fc3d455479675609cd7c19dbc69.jpeg

And these are the variables that are added to the “MasterInventoryClass” BP:

e65a5c540c8ae7e3e83e825434530c2cf5b93f62.jpeg

This is the only BP that is located in the root “Blueprints” folder:

63e620fc38e277def35bcf158d0688609b730f25.jpeg

Two Generic Enums that apply to most item types are in the root “Enums” directory:

Enums.JPG

ItemTypes:
ef8c2e65b479bdd6cf38c116fedb21f715067444.jpeg

MaterialTypes:
5b045639a14eb9ac00423fa4f6ea8eea3aa82e26.jpeg

(in case you want to automatically determine item durability and lifespan etc)

Three Structs are in the “Structs” folder, one for each basic type I set up:

e96773f6b0197910faa308b3ca556c05faf7ed8e.jpeg

So now whenever I make a blueprint based off of “MasterInventoryClass” I get access to all those variables. Here is an example where I created a Helmet item. I placed this BP in the “Blueprints\Armor” folder.

64c941559d3c6d6788632fba6c5f5170f233f2c6.jpeg

Notice that the armor BP has all the variables for weapons and character modifiers as well, but you simply don’t need to define them for any items where those settings do not apply.

I also wanted to show how a system like this can be somewhat flexible. Notice that the armor struct has a variable called “Buffs”. That is an array of class variables to “MasterInventoryClass”, and it lets you create an item for a character modifier and also stack them as modifiers on top of any other items. So here as an example is a helmet that would be very strong but reduce player speed by 50%.

If we look at the “SlowBones” blueprint we can see its “Character Modifier Properties”:

b6a243be9214d7a08b6d3c807ca6878597f6b753.jpeg

Note that currently this will let you put any inventory item under buffs. You could easily restrict that by having another sub-parent class called “MasterBuffClass” and make the buff variable an array of “MasterBuffClass” rather than “MasterInventoryClass”… but it doesn’t really matter since you could either enforce it by hand or just check that the ‘buff’ item is actually a character modifier and not a weapon etc.

Obviously this is all super rough and lacking in implementation details. There are a bunch of ways you could organize it from here. I would probably have most of the basic scripting happen in the parent class with something like this:

849b37e36d3cd91cd2476981170dc06da8ada65e.jpeg

You could then do further sub-switches based on the separate types of each item, and then once you get down to common types, its all the pure variables that define what happens. Ie, if you have armor, you need to figure out what type (is it a helmet or breastplate) and decide how to modulate the players incoming damage. You might opt to store a variable for how much each part of the body is procected and then you simply modify the corresponding variable any time the item armor is changed. And then the buffs need to get read but you pass that in as if another item was selected so it does not complicate the script. Then you can easily get all sorts of stacked effects going on.

Another image showing a hypothetical Weapon BP so you can see what type of weapon struct settings you might want to use.

weapon_struct.JPG

Notice here again that there is an enum for Melee vs Projectiles. Then there are two more enums defining the types further below that. If you selected the Melee type for the broader category, then the “Weapon_Projectile_Type” will not matter since it wont be used (due to the way you set it up using switches on type). But since this is a melee weapon, it can further specify that it is of type “Knife”.

Of course whether or not there is a benefit to making “knife” a whole type or not depends on how many knives your game needs to have. I like to break things up in case of future expansion.

Anytime you need to access these vars elsewhere you simply have to Cast to “MasterInventoryClass”. And then you could have a switch on ItemType after that in order to filter the behavior elsewhere.

Wow, it looks like you put a lot of work into this. Thank you so much for the example. What was really throwing me off was that the inherited variables and functions were hidden and I had no idea that they were inherited. I have found how to unhide them and what you were saying makes so much sense now. Also, now I am learning about switches and enums from you.

Again, thank you so much for your help over the past few days, Ryan. And thank you to everyone else who pitched in.

Yes, that example clears out a lot of what I was confused about. That actually opened up my idea for my development to a much easier route.

Thank you.