I want the designer to be able to chose the main mesh type for an actor in bp, the c++ code needs the main mesh and the actor can have many meshes of different types, I know I can use tags or any other way, but I’m curious if I can add component dynamically and have that visible in bp.
what I could reach so far is creating the component and assigning a mesh to it but it doesn’t show up in the component list in BP editor, it show in level though, and it can’t be selected to modify it, is there a way to do this.
It kind of seems like you want an actor that has the skeletal mesh of a weapon if that’s what the artist wants?
I did something similar where I do just that. I create an actor that is fully set up in blueprint and I don’t do any special logic in c++.
I’ve seen many people create systems where you have to specify what skeletal mesh to use on a hard coded skeletal mesh component that’s part of the actor.
But you can leave the actor actually blank and let all of that be completely set up in editor by the artist by letting them create the whole hierarchy how they want. Now you have the flexibility to add some unconventional things like a light that shines at the end of the gun’s mesh while a particle system is spewing out of the gun barrel and some sound emitting component is also playing. Yeah, 99% of the time you probably will only have a simple mesh but it’s actually not that hard to just add a mesh component to the actor in blueprint.
Also you would spawn components at run time something like this:
//Some additional setup goes here, like setting up what component this new component is attached to, and any other properties you want to set initially
//now register the component
MyNewComponent->Register();
I understand what you mean and for most cases we don’t even do much with the mesh and its only there just for reference or whatever, however some few cases will require a choice between static mesh component or skeletal mesh component as a main mesh and that mesh will be needed at code later on, while also having other meshes components within the actor, so get component by class won’t work, and relaying on a tag might be error prone, its much safer to just create a default mesh.
However creating both just in case the art is actually one of them is unneeded redundancy and confusing.
And its not just the mesh that relay on the art, it could also be a particle system component vs a niagra component.
Knowing which component type to add can help a lot specially if c++ code relay on it.
I was hoping to know how to add the components to appear in the component list in the editor as if it was added there and replicating the behavior of CreateDefaultSubobject, if its possible of course.
I don’t think you can actually do that. The components that appear in the editor are literally part of the actor hierarchy.
I’ve done something similar where I create an actor for my weapon’s physical representation in the world. It acts like a weapon pickup or it can be the actor attached to their hand when being held. I then add a component to this actor that helps manage finding the skeletal mesh if one exists, so it’s easier to play animations on it, for example. That component also takes care of a bunch of other random things like enabling/disabling physics on the entire actor hierarchy if there’s also an attached magazine, for example.
Yes, I think its impossible too now after taking a look at CreateDefaultSubobject, or at least it will mean changing engine code, and I wouldn’t even know where to start.
I think using tags is my only option now, thanks a lot for your explanations and time.
You could by default have it find the first skeletal mesh or static mesh which will work for you 99% of the time and not rely on tags. You can add a property that lets you manually assign the right reference if doing something special though.
That 1% can cause lots of troubles that can’t be detected cause it works 99% of the cases, can’t just wish that the first mesh component to be added is actually the weapon mesh.
The reference was a great idea, I set it in BP Construction Script and it did the same as what I was trying achieve, also added a Tag option just in case, just will have to make sure whoever uses it knows how to correctly do it.