The Situation:
I have a Pawn with the intended functionality of being able to transform into many different objects - however, these objects come in many different shapes and sizes, so I need to be able to change the collision type of my pawn at will.
The Problem:
I can’t seem to find a way to change the collision type in the editor with a drop down variable, let alone change it during runtime, with C++ code. What I’ve tried so far is below…
My Attempts:
-
My first idea was simple polymorphism - use the UShapeComponent as the root so it could point at any type of simple collision shape, but unfortunately, Unreal doesn’t let you do that. The UShapeComponent will not show up in the blueprint as the root, or at all for that matter, and will often set another component (like the mesh) as the root by default, which defeats the purpose.
-
My second idea was to keep a variable of each collision type and switch them out for the root whenever changes are made. However, I need a default collision added in the constructor, but when I do this, I cannot find a way to remove it, so it still exists when I switch the root out for another collision. I also have no idea how to create and keep information about a collision in code, and then add it to the editor at will - I’ve only been able to figure out how to add a component in the constructor with
CreateDefaultSubobject()
or withCreateObject()
.
(Note: To make the work easier for designers, I planned on making a drop down to select which collision to use, then I would change the root in the PostEditChangeProperty
and remove the old one from display, but I can’t seem to figure out the removal part - and even when I do, how do I add a new component to take it’s place?)
The Question:
So, how would I go about doing this?
- Can I actually use UShapeComponent as the root, but just have to make some tweaks?
- If ^that’s not possible, how would I initialize the each collision type without adding them to the Blueprint hierarchy and then how would I swap them out with each other for the root component (only ever showing 1 collision at a time)?
- If neither of those are possible - What can I do to get the desired result?
Ideally, I would like a nice tool for designers to use with a simple drop down to switch between collision types, and have C++ code handle the information for better workflow.