This is more a problem of me not knowing what to search for, and looking for the way. In C++, when I create a component and add it to an actor, at runtime everything works as expected. The problem that I am unsure of is related to the editor.
If I open an actor blueprint and add a static mesh component to it, when I change the static mesh it appears in the viewport of the blueprint. Also when that actor is placed in the level, the static mesh is visible in the level.
If I create an actor and add a static mesh component to it through code, it is created correctly and at runtime it spawns the mesh correctly. However, I do not see the mesh in the viewport, and when I place an actor in the level, the manipulator widget appears correctly, but there is no mesh. To be explicit,
Create actor in C++
Add static mesh component in C++
Derive blueprint from actor
In editor, set the static mesh component
Static mesh does not show up in viewport
Drag blueprint into scene
Static mesh does not show up in the scene
My guess is there is another step, but I’m not sure what to search for to find that step. I only find pages related to creating and attaching components. Can someone point me in the right direction?
I never found out the solution to this, so we have worked around it instead. If I need something to show up in the viewport, I have been adding those components directly in the editor. For components that were added in C++, we can select and move the transform in the editor, but you will not see the associated object.
So, I just tried this again with the following code. This works as expected. We are using a custom build of 4.14, but we have not made any changes to “fix” this issue. It appears to have fixed itself, so it may just require a restart of the editor and/or PC.
Create a blueprint from this actor. Open the actor in the editor. Set a value to the static mesh component. The viewport, which previously did not display the static mesh, is now correctly displaying the static mesh.