Getting information from actor?

Hi! I’m currently working on creating my first inventory system, but I’m running into some issues. I’m currently stuck on using the item. I have created a blueprint interface for using the items but I’m not able to call the interface message unless the actor is spawned in the world. This is hard to explain so I’ll add some screenshots to further show!

Item’s Blueprint : Screenshot - 51f75c91c4ab13fc78f69717542e2165 - Gyazo
Use Event : Screenshot - 4dc72b7ff310c144c14fdfcb21a0ce09 - Gyazo

The only way this doesn’t fail is if manually put the actor in the world otherwise, the cast fails. Is spawning every actor that needs to be referenced at random times common practice? If not, what’s the best way to go about this?

This was hard to explain so please let me know if you have any questions!

EDIT : Some more information : The item is placed in the world, as a pick up item. So the actor is there but as soon as it’s picked up, it destroys.

If what you’re doing here is selecting an inventory item and intending to call functions it contains then yes, you can absolutely spawn the appropriate actor on selection, and destroy it on deselection or on “Expend”. All of your inventory items should inherit from a common base class that contains the interface you’re using as well as the “Expend” functions you intend to call.

Hmm, I read this and thought I knew exactly what to do, unfortunately, I didn’t and I’ve run into some more issues. Could you possibly explain a little more as to what you’re explaining? If you have any visual references, that’d be awesome too! Thank you!

A little off-topic, but are you using some form of skin for ue4? Kind of interested in which one if so

How I used to make my primitive inventory was when I needed to call anything, I’d spawn the actor in and run their command. After that was done I’d delete it again if needed and made sure the UI/database go tupdated. This isnt flawless ofcourse but it did work fine for me

More detail on the solution I alluded to in my last post:

The Inventory
At it’s core, is just an array of structs that contains the data about the MyCollectableItem it represents. It should have all of the data about the actor in order to recreate it.

A base class for all items that can enter the inventory. It can have functions like “OnInventorySelected” or “OnInventoryUse” or “OnCollected” that do custom behaviour, and can be called by the inventory manager / widget.

Inventory Interaction
Such as in your example, you are “Using” an inventory item. What this item does should be implemented in the inheriting MyCollectableItem blueprint/class (e.g. BP_HealthPotion). How can you get access to that information? You spawn the selected item from the class data saved in your struct (e.g. BP_HealthPotion) and call the “OnInventoryUse” function. The actor will perform its unique task (such as increase HP by 100).

Potential Flow:

  1. UI Selection of Inventory Item
  2. Spawn the relevant actor, give it the struct data if necessary. Save this actor reference.
  3. Tell the actor that it has been selected “OnInventorySelected” if necessary, (for example, equip the weapon)
  4. Player presses to “Use” the item. On the spawned actor, call “OnInventoryUse”, (for example, drink the health potion) remove this item from the inventory, or use 1 quantity if you have stacking items.
  5. Player selects a different Inventory Item - Destroy the saved actor reference, if valid, and repeat at step 1.

If you are accessing lots of unique actor values that aren’t default values, e.g. you’ve placed many collectable actors and, in level, changed their default values. If that is the case:

Never destroy the actors, but make them inactive and invisible. That way you only need a reference to them in your inventory, and you could toggle its inactivity status as you want that item to exist again.

This is because the data you want to store in the Inventory Struct shouldn’t be specific any actor. This generic data could be numerical values, which actors can parse into variation, or an index for swapping a mesh. The actor should know what to do with the data it receives.

Otherwise check out my comment on the other answer.

No worries! Yeah I’m using this skin and Electronic Nodes in Code Plugins - UE Marketplace this for node wiring!

Thanks! It looks pretty sleek adn more “modern” then normal ue4

May the delay be your GuidingLight. There is no 0.0. I’ am resolving a lot of problems in that way. What kind of game you working on by the way?