Child classes have different functions

Hello there, I have an inventory system and I want the items to have different functions when held. By this I mean weapons should swing or fire, placeable items can be placed or rotated, food items can be eaten to replenish hunger and more.
I’m asking how I can make the basic difference between item actors so that they are all children of a base ‘Item’ class but different child classes of that base class have different functions such as being placed or thrown.

Thank you

Create an event in the base item class named “use”, and leave it as empty.
each child class implements that event differently.

Thank you for the reply. How could I make other actors have more events. Food items will only need the ‘use’ event like most actors, whereas placeable item would need the ‘use’ event and a ‘rotate’ event, weapons would have the ‘use’ event and a ‘secondary’ event and potentially a ‘reload’ event. All of these would be called from the player yet I do not want the player to have loads of events for every possible item that are not used for most actors.

So you know what I could do about this?

then you can use interface.
for example,create 3 different interfaces called “food interface,weapon interface,place able interface”. Each interface has their own function definitions.
the base class does not implement any interface and have the children to implement one of the interface.

each interface might have 2-3 functions (as you mentioned).

Would I then have all of the events in the player blueprint for ‘use’, ‘rotate’, ‘reload’ etc and check if the actor implements those interfaces or is there a better way to do this.

I ask this because I could then call the rotate event on an actor that does not have that interface.

perhaps this is the way to go.

you should know what you’re holding first,in order to call its events.
for example,now the player is holding a bread ,you can call “eat” event in “food interface ”. It’s not possible that you call fire event when you holding a food right…?

but that’s all a suggestion.
it’s still depends on how you plan the system…

Its more I do not know what to do with the input events as I can call the ‘reload’ input event for a food item but it won’t ever get called on the item. I just feel that being able to call these input events that will do nothing is bad practise and is un-optimised.

wait a minute…

well,we have 3 interfaces.
you could put fire and reload in weapon interface.

not sure if I understand what your concerned.

but it should not happen that interfaces gets called wrong and do nothing.

those events should be player’s decision.

there should be a button that says “eat” for player to click on or something first.the according event gets called secondly.

If I am holding a food item and press the reload input. The reload input would then check if the actor I am holding implements that interface and then calls the appropriate event if it returns true. I feel this should not be needed as most of the time this event would be called on an actor that does not use this interface making the input event not do anything but still effect performance.

Sorry but I do not know how to better explain it.

what impacts performance is what it actually doing.
an if brunch doesn’t impact anything I promise you :grin:

for a simple way have one function lets say Use that has an input of type GameplayTag or Name, then on Use pass through the tag you want, (consume, fire, reload etc)

then the child actor can switch on Tag or completely ignore if its not relevant

Thank you so much for the help, I think I try to keep performance cost down to a minimum even where it is not needed so thank you.