Hello everyone. I have a base blueprint called “BaseBuilding”, and all of my blueprint buildings inherit from it. I would like to set up component hierarchy so that every building has a static mesh, and a box component. I want buildings, however, to define details of said mesh and box component. use case is this: I want BaseBuilding to implement function for people entering and exiting building on collision with ‘entrance’ box component. So instead of defining two functions in every building, i want it to be generic for all BaseBuildings.
So problem is this: Buildings that inherit components cannot override/define them! I need each building to have it’s own mesh and define location of entrance box component. How can i accomplish this?
When my line trace returns a BaseBuilding, my character will move to BaseBuilding’s Entrance Box collider. So all inheriting buildings will implement their own location of collider. If BaseBuilding didn’t have box, i would have to try casting it to one of my multiple buildings before calling MoveToEntrance function.
Hey Makotech,
Instead of giving BaseBuilding a Mesh and Box Component, you can create new Mesh and Box Components in its Construction Script. Buildings will then create components in their Construction Scripts, and they can be overridden and defined after that.
Hope that helps!
Not exactly. Certain functions require that my BaseBuilding have a box component. All of my buildings inherit from it, so when i click on a building, my line trace returns a basebuilding.
I solved this issue, however, by requiring my BaseBuilding to have both mesh and box component. Then, in my Inheriting Building BP construction script, I basically copy defined mesh and box from Building BP to it’s inherited mesh and box. Its working well, but its kind of a round-a-bout way of doing things.
What functions require box component before Construction?
Ah, I see. solution you reached is probably how I would have done it as well. It may seem round-about, but it’s easiest way to avoid putting those functions in each Building blueprint and to avoid casting to each Building. Unfortunately, TSubobjectPtr’s can’t be made editable, so finding creative ways around situations like this are necessary. Glad you got something that works for you!
I’ve found an interesting thing; a bit of a way to resolve this issue. I noticed that i can create a C++ class based off of AActor, and add in a field for a mesh. Then, ill build a blueprint which parents off of this C++ class as my basebuilding class. I can then make more blueprint parenting off of basebuilding, and ill be able to set my mesh component in each individual BP. This is because mesh is a native C++ component, and apparently, can be overrided in child blueprints.
So in effect, i do AActor → C++ class basebuilding → BPBaseBuilding → Barracks/house/church BP. Then i can override mesh.
It would be nice if this can be done from blueprint without needing C++ class. Adding components in blueprint should maybe just be considered a native C++ component instead of what it currently is.
Hey Makotech,
Thanks for workaround!
There is currently a feature request in our system to allow altering of inherited components (UE-2584), but until then it’s nice to know you were able to find a way to do this through C++. I will let you know if I see an update on that feature request. Thanks again!