I’ve a parent class that has a box component with overlaps events to allow the player to interact with items, but one of my items requires multiple of these overlap box’s so that the player can interact with multiple parts of the object, is there a way i can share the functionality without duplicating the code?
Make a generic object and you can stick it into anything, instantiate it as a var-ref, class-ref, etc.
I’ve never used an object tbh can explain a bit more? Do u mean that i should put the code in object and then call that code from actors?
Make a new blueprint, type of ‘object’. it’s the most generic container, it can contain variables, functions, macros, etc.
Since it’s a class/thing, you can make a variable with that type of object reference, or better, a class-reference. if you make the base-object a template with the basic-stuff you can create a child-class with specific settings for any variables or whatnot, like a generic weapon-class that each child is a specific kind of sword or whatever you set the settings to be. Instead of working with the base, you can pick a child knowing they are of the same ‘thingness’ and the child inherits all the stuff from the parent.
In your case, it might depend on what you want to do with the various boxes or whatnot, but making an object (or actor component as you might need to) allows you to at least template/generify all the shard components and behaviors; make one base-thing with all the common-parts, and children can be use to make something more specific (setting vars, etc) and/or more functional (overriding parent functions or adding new ones).
In your case you might want to make an actor component so it can be added to actors like CharacterMovement. Add a collision box or whatnot, the event or two, etc, then pepper them across your larger object. The idea here being that each box will be a duplicate of the others, otherwise you can always make different children as you might need to.