C++ editor spawn static mesh

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?

Thanks.

I am experiencing the exact same behaviour and would appreciate any insight into the reason or the solution.

Would be nice if any off you can provide source Code. We are not Mindreaders after all =)

(Upload to www.pastebin.com or similar sites)

@MC1RScorpion

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.

Are you adding the component in the C++ constructor, or within another method?

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.

//
// VRPlayer.h
//

UCLASS()
class SHARED_PROJECT_API AVrPlayerTestPlayer : public APawn
{
  GENERATED_BODY()

public:

  AVrPlayerTestPlayer(const FObjectInitializer& ObjectInitializer);
  ~AVrPlayerTestPlayer();

  UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "BRB|Actor|VrPlayer")
    UCapsuleComponent*  SceneRootNode = nullptr;

  UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "BRB|Actor|VrPlayer")
    UStaticMeshComponent* VRDebugStaticMeshPlayer = nullptr;
};

//
// VRPlayer.cpp
//


AVrPlayerTestPlayer::AVrPlayerTestPlayer(const FObjectInitializer& ObjectInitializer) {

  SceneRootNode = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComponent"));
  SetRootComponent(SceneRootNode);

  VRDebugStaticMeshPlayer = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent"));
  VRDebugStaticMeshPlayer->AttachToComponent(SceneRootNode, FAttachmentTransformRules::KeepRelativeTransform);
}

AVrPlayerTestPlayer::~AVrPlayerTestPlayer() {

}

///-------------------------------

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.