Whats the best practice to map use functions to items

I am trying to implement the ability to use held items. I don’t know whats the best practice to do this. and what class to use for the items.

When i use actors for the items i have the problem that every item in the inventory also has a world transform which makes them bound to the level i guess. Also i do not need a visual representation because thats what the itemdrop bp is for.

When i use the Object class with functions i have the problem that i cannot use functions like line trace inside the items …

I tried using actor components for the items but that does really not seem right for the inventory system. Since my inventory is an actor component on the player i would have to add the itemcomponents to the player instead of the inventory (because its no actor)

So the last thing i know are structs which would fit nice since most stuff ist just item data. But how do i map a function for example from a blueprint function library to a struct? Using Strings for the function names seems like bad practice.

Can anyone lead me to the right path?

edit:
i saw a version where u spawn an itemeffect actor that does what u want on use but in my game i will use the item repeatedly very fast so i am not sure if spawning multiple actors per second is a good idea

all those options are fine it just depends on your game,

i use UObjects myself, you can add world context to them in c++ to have any functionality like LineTrace, or just call the trace on a manager class

if you dont wont to do that actor components, feel weird but actually work and are far more efficient than spawning.

that said spawning is still fine too, or better yet use ObjectPooling, the advantages to actors is you can add say a particle effect or something

if you want to map it to a function library or some manager class i use GameplayTags instead of strings

i use actor components now, i just add the components to the player from the inventory bp and hold them inside an array. I was initially against this aproach because i did not want the player to fill up with items in the inspector but since i am rarely looking into the components on runtime it does not bother me.

thanks for encouraging me to try the component version again

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.