Download

Creating an interactable item system - question.

Here is my general strategy to create a parent class that will be the fundamental setup for my interactable item system for my game:

J98cHu4.png

Does this seem like a reasonable way to accomplish my goal of creating a system for items that will allow the player to perform various actions on an item depending on what exactly it is?

For instance, a door would have the available actions: activate, lock, unlock, destroy.

Whereas a computer terminal would have: activate, hack, and destroy.

This could be accomplished with interfaces inherited from the parent class, and tweaked for the actual child to respond to or ignore the irrelevant actions?

Or am I going about this entirely wrong?

As always, thanks!

Have a look at the content examples physics level. It users the player controller and with the trace will return multiple different results depending on the object it hits which will then cast the appropriate event over to that object.

Is that a best practice or is it more of just a hacky way to do things?

It seems like organizing things the way I have above would be more robust, but it may be unnecessary?

Bokuden, I rather like how your setup works, and from an organization stand point, I think it would work well. Basically you could create each action on the master Actor, and then just set each child to only use certain ones. It’s similar to how I set my RPG for mining nodes, logging, chests, and so on.

That was exactly my thoughts Hakabane!

The child actors would only respond to relevant actions when called.

Are interfaces the appropriate communication method here?

I generally don’t use interfaces myself and instead just cast. I’ve heard that both have good uses and I should probably use each one where it should be needed but I haven’t run into issues yet that I can see.

Basically you just need a way on your child actor to tell it which of the functions are allowed and which aren’t. Typically I just use bools for this. I will have to dig through my projects to find exactly how I have it set though as I am currently reworking about 10 different projects into one massive project so my stuff is all over the place.

I will post here again if I find it, but I think you have a pretty good grasp on how you could do it.

Alright cool, thanks for the feedback Haka!

On a slightly related note, I have found that making actor components that do specific things, like add health to an object (like a player character) or fire component that burns and causes radial damage to whatever it is attached to, seems pretty robust as well.

Something I would like to investigate further, now that I am thinking about it, is the exact nature of Cast To -vs- Interface.

Sadly the only issue with actor components is that replication with them, from what I’ve used them for, is basically non-existent and it bugs me to no end. I’m still learning with replication but it does not allow the switch has authority node so I just spawn an AActor and attach it to my player and do everything that way.