x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AddActor in the editor via C++ module

Hi I'm trying to place some actor in the map via C++. The code runs in a secondary module associated with a menu item in the editor.

 void FLevelStreamModule::OnMenuEntry()
 {
     AStaticMeshActor* CubeActor = Cast<AStaticMeshActor>(GEditor->AddActor(
         GetWorld()->GetCurrentLevel(), AStaticMeshActor::StaticClass(), 
         FTransform(FVector(0))));
     CubeActor->GetStaticMeshComponent()->StaticMesh = LoadObject<UStaticMesh>(nullptr, 
         TEXT("StaticMesh'/Engine/EditorMeshes/EditorCube.EditorCube'"));
 
     GEditor->EditorUpdateComponents();
     CubeActor->GetStaticMeshComponent()->RegisterComponentWithWorld(GetWorld());
     GetWorld()->UpdateWorldComponents(true, false);
     CubeActor->RerunConstructionScripts();
     GLevelEditorModeTools().MapChangeNotify();
 }
 

The actor is is visible in the scene outliner but the mesh is doesn't appear in the viewport. But when I change any property of the actor from the editor it magically start drawing. How can I notify the editor to start drawing my cube?

Product Version: UE 4.8
Tags:
more ▼

asked Jun 23 '15 at 10:32 AM in C++ Programming

avatar image

omigamedev
85 9 7 17

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I've run into the same issue and figured it out.

You need to call "MarkComponentsRenderStateDirty();" on StaticMeshActor.

Also, you don't need to call EditorUpdateComponents and the rest of the functions.

You only need:

"CubeActor->GetStaticMeshComponent()->StaticMesh = LoadObject" Followed by call to "MarkComponentsRenderStateDirty()" and that's it.

more ▼

answered Oct 19 '15 at 02:33 PM

avatar image

NegInfinity
99 13 17 29

avatar image awbrenn Jul 27 '17 at 07:23 PM

It looks like setting the StaticMesh component of an actor directly is soon going to be deprecated. I'm running 4.16 and getting a warning. I ended up using this.

CubeActor->GetStaticMeshComponent()->SetStaticMesh(LoadObject(nullptr, TEXT("StaticMesh'/Engine/EditorMeshes/EditorCube.EditorCube'")));

If you use this you do not have to use "MarkComponentsRenderStateDirty()"

Thanks for the post. I was lost without finding this.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question