Dear readers,
I would like to make an abstract base actor class (derived from AActor), which has a single collision component. This class will be used as a parent for blueprints which implement a specific actor. What I would like to do, is to give the creator of such child class the option to change the shape of the collision component. For now I have made an UENUM (EShape) and exposed a variable (CollisionShape) of the base actor class in blueprints that can hold values of this UENUM. In the construction script of the base actor class, I create a default sub object of a class which depends on ‘CollisionShape’ as the collision unit. Screenshots are shown below.
However, this method always generates an UBoxComponent (the default option) as collision component which implies that setting CollisionShape does not influence the collision component at all. I’ve got a feeling this is because the construction script is run before any variables are processed and does not run again after recompiling the blueprint. Then again, I could be horribly wrong. If would be great if anyone could shed some light on this issue.
Furthermore, I have tried overriding ‘OnConstruction()’ and 'PostInitializeComponents() and putting the logic in these functions. However, these attempts resulted in mostly errors. Therefore, the main questions I would like to ask is: Is it possible to set a blueprint selectable collision shape from a C++ derived parent class for a collision component, granted it is the only collision components of the actor? If so, in what (overridable) function should I put the logic for this? As a last resort, I figured I could make three separate base actor classes, each with another collision shape. Of course, this is not really an elegant solution due to redundancy, so I would like to avoid it.