Need help with making a universal interaction script for interactables in my game

I want to create a system that would allow me to initiate all of the interactions in my game. A potential solution I have is to create a script that would create a hitbox around objects I that would display an interaction prompt as soon as the player collides with the object’s hitbox. However it seems tedious to attach that script to every interactable object. Is there a better way to go about this? Here’s something I put together manually to show roughly what I want to turn into a modular process for every interactable in the game:

For this thing best is:

  • use parent class actor. So code all your interaction in actor BP that has only things for it and some debug stuff
  • create child class actors from that base class
  • all child actors will inherit all code from parent class

now you need communication from parent class:

  • variables you can just read in child class
  • functions you can just use
  • however about events: you either make interface in child class, or make event dispatcher in parent class. Not sure if there is a way to just simply listen to event in parent. Well maybe there is, you probably can override parent event (but never did it in blueprints, so do not keep me accountable for it|).

PS.
you can also use blueprintable actor component or scene component, however those add a lot of “boiler plate” ie. code that may be quite messy and overcomplicated compared to what components provide.

pps.

Yellow Rubber Duck to the rescue (aka chatGPT):

:white_check_mark: 1. Event Override (Polymorphism)

Best for core behavior that needs to differ per child.

  • In the parent (BP_ParentClass), create a custom event (e.g. Beep) and call it somewhere.
  • In the child (BP_MyClass), use the “Overrides” dropdown and override Beep.
  • When Beep is called in the parent, the child’s override will be used if it’s running.

:green_circle: Clean and simple. Only works if the child is intended to override the behavior.

imo that event override is best and easiest (as long as you rememmber it is ovverride event, so put comment clearly explaining it for your future self wondering what this even does in few months)

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