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"

Problems spawning an Actor in C++ for use in the editor

I'm creating actors via command line in the editor through the EdEngine Exec. The actors I create go into the editor, not into the game realtime (I'm generating actors with components based on command line parameters). I'd like to be able to modify them in the level once they're created as normal: modify parameters, location/rotation, copy/paste, have it be saved in the level and loaded like any other actor placed in the editor.

I'm using the basic:

 NewActor = InWorld->SpawnActor<AActor>(AActor::StaticClass());

Then I add some components. For example:

 UInstancedStaticMeshComponent *SMComp = NewObject<UInstancedStaticMeshComponent>(NewActor);
 SMComp->RegisterComponent();

and I call SetFlags(RF_Transactional); on the actor and the components.

Problem #1: I can't modify any properties on the components in the editor. It says native components need uproperties. There is no C++ class for this. I simply spawn an empty actor into the level and add components on the fly.

Problem #2: If I spawn my actor with a name (using FActorSpawnParams), and then I try to spawn another actor with the same name, instead of increasing the counter on the name like it normally happens in editor, it doesn't spawn anything and SpawnActor returns the actor that already has that name. I'd like to give it an arbitrary name that automatically counts up when I try to place more of them.

Problem #3: If I add two Instanced Static Mesh Components to one actor, the second one shows up in PIE but not Standalone. If I set RF_Standalone on the component, they'll show up in Standalone mode, but not in the packaged build, and playing it in PIE hits an 'ensure'.

Problem #4: Copying/Duplicating the actor, doesn't Copy/Duplicate the Instances array in the InstancedStaticMeshComponent. This problem also happens if I create the actor and components directly in the editor, so it's not a C++ problem. I'd like to be able to copy and/or duplicate these actors though.

Problem #5: Can't move the actor from one sublevel to another because of Problem #4 (apparently Unreal copies, deletes, and pastes to make that happen). When I say move, I mean assign the actor to a different level, I don't mean change the location. Like, select the actor, click on the level editor, select the level you'd like to move the actor to, right-click it and select "Move Selector Actor to Level".

Is anyone familiar with spawning an actor for in-editor use? Any ideas?

Product Version: UE 4.12
Tags:
more ▼

asked Aug 03 '16 at 06:51 AM in C++ Programming

avatar image

rantrod
1.5k 47 47 215

avatar image rantrod Aug 03 '16 at 09:04 PM

Problem #1 is solved. Right after spawning the component set: SMComp->CreationMethod = EComponentCreationMethod::Instance; and I was able to modify the parameters as normal.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first
    1. Call NewActor->AddInstanceComponent(SMComp) to set the creation method and add the component to the instance components array.

    1. That's the problem with names: they are supposed to uniquely identify objects. Use SetActorLabel instead if you want to set in-editor labels that can be the same. Use MakeUniqueObjectName to generate a unique name.

  • 3-6. I think most of this weirdness is caused by the object not being in the instance components array. Try calling AddInstanceComponent and see if these issues persist.

more ▼

answered Aug 04 '16 at 03:13 AM

avatar image

Digi Labs Dan
561 16 10 34

avatar image rantrod Aug 04 '16 at 06:40 AM

Thank you so much dbuchoff, that was awesome! Most helpful answer I've gotten in these forums yet!

The only issues is (4),(5) but those happen even if I create the Instanced SM Component manually in the editor. The instances array doesn't get copied, which is weird, but nothing to do with my code.

avatar image Digi Labs Dan Aug 04 '16 at 07:05 PM

hmmm... that's odd! I'm seeing that problem too: duplicating an actor with a ISMC "forgets" the instances.

I have no idea why it's like this, but I'm fairly confident it's because UInstancedStaticMeshComponent::PerInstanceSMData is marked DuplicateTransient. You may need to populate the instances with your own Construction Script in order to make this work right :-(.

(comments are locked)
10|2000 characters needed characters left
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