Get Actor Of Class (Inventory question)

Hi! I have a problem when I try to use an Item from Inventory.

To store information about my items in inventory I use a structure that looks like this:

To use an item I call an actor of class to define an item and use it. It is choosing an item BP based on actor

So my problem is that I thought getting an actor of class is getting the actor that I stored but it gets a random actor from this class (or not random) and problem occures when I pick up the last item on map and want to use it. It can’t find any actors and nothing happens when I use an item. Can I somehow save the reference to this item in ‘Item Info’? I tries creating an actor object reference but it didn’t work.


I think I can always have a copy of every Item for this purpose but I’m sure this is not the right solution :sweat_smile:

That is what the nodes does:

Find the first Actor in the world of the specified class.

Stored where?

Also regarding class variables (purple variables):

Thanks for the video! Actually I was not right when talking about storing.

So when I pick up an Item I destroy it and save its information with structure but I can’t get an actor if it’s destroyed I guess, however saving Item’s class is working and I thought I could call an event from class but it’s not working so I have to get an actor and then call the event. And I can’t call an actor if there’s no item left on map

Basically I want to save an Item info in structure so I can call it’s event, could you help me how to do that?

Thanks for your reply!

Well I mean, I’ve already done it and it works but isn’t this messy?

You mean like the item gives the player an ability?

Class variables will only allow you to load an asset. You can’t call a function if the object is not loaded.

Idk what that event is supposed to do, but probably it should not be in that class. Consider moving that event to the class that is spawning / calling / destroying that actor? You can “enable” that event when the actor is picked up and “disable” when called X times…

You could also spawn another actor that sole purpose is to do X, then destroy itself. It’s more or less what you are doing, but you should let that actor manage its own lifetime. For example: create a parent class with a custom destroy event, then create child classes with custom functionality that when they do what they are told to do, they call the parent event to destroy themselves. This way the struct can hold all those child classes in the same single variable for you to spawn, they’ll do X automatically and destroy themselves.

So ideally you would have an item class with child classes of different items and an ability class with several child classes with custom functionality. Item child classes could assign the player a unique pre defined ability to spawn and do stuff.

Thanks for your reply !

I think I already have this
I want to make it clear and explain my logic so please have a look and sorry!!

I have a parentBP and childBPs and also BP class + structure

Base logic of what happens when I pick Up Item (parentBP)

When I want to use it I am going through this code (This code is placed in inventory slot with item info)

‘Use Item(Master Pick Up)’ is an event in BPclass, so based on object it is executing an item effect that is used.

This is what happens in ParentBP when I use the item

Items are just damaging and healing the player for now

Sorry I didn’t understand what do you mean by managing it’s own lifetime
When I spawn actor I already spawn child class actor (specific Item that I need) for only this purpose as you said and then delete it

How are you managing health? If you are using a health component, maybe just move the logic to heal there?

It’s my first project so I’m not sure but I just have a variable with health and use anydamage for damage and heal.

damage/heal in ParentBP

logic in thirdpersoncharacter