I currently have a system to put hats and other cosmetics on the player character by attaching a new mesh to a socket on the Player Character when activated by a trigger.
When wanting to swap a hat for instance that goes on the same socket, how can I remove that old hat so the new one is not clipping on the old one?
These are currently set on separate blueprints (each blueprint is a set of items that attach and swap the player’s appearance at once), is it possible to remove a component that is attached to the Hat Socket?
I can do my best to explain further, and any help is appreciated.
After adding the Mesh Component, you can right click “Return Value” and “Promote to Variable”, renaming something like “Current Hat”. Then, you can do anything with it using “Get Current Hat” and it will grab that static mesh for your use!
Before adding the NEW hat, check if “Current Hat” is Valid (Get, right click it, “convert to validated Get”) and if it’s valid, Destroy it. If it’s NOT VALID, that means there isn’t a hat to destroy, so proceed normally. This is to prevent a Null Reference (and therefore prevent crashing).
I turned the Return Value into a Variable, but I can’t convert the “Get” node into a “Validated Get.” I’ve looked it up and I see that it should be right there in the right click drop down but I don’t see it.
First we have to make the distinction between Static Mesh and Static Mesh Component.
The Component is what is attached to the character it has a bunch of data related to where exactly it is and how it moves. It is a kind of a “holder” for a Mesh. (grossly simplified)
The mesh is just a bunch of vertices, faces materials and such. (again grossly simplified)
This means that you can have a Static Mesh Component without a Static Mesh!
So you can have a bunch of components already attached to your character with no meshes assigned to them and you just switch the mesh when needed like that:
Now you’ve decided to create the component runtime. That might be ok in some cases but in your current setup I don’t think it is needed. If you are hell-bent on crating it runtime @Mind-Brain is completely right you just do it once and store it in a variable.