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

**URL:** <https://forums.unrealengine.com/t/problems-spawning-an-actor-in-c-for-use-in-the-editor/365962>\
**Category:** Asset Creation\
**Tags:** command, spawn-actor, Instanced-Mesh, unreal-engine, question, CPP\
**Created:** [August 3, 2016, 6:51am UTC](https://forums.unrealengine.com/t/problems-spawning-an-actor-in-c-for-use-in-the-editor/365962 "2016-08-03T06:51:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rantrod](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rantrod](https://forums.unrealengine.com/u/rantrod)\
**Post date:** [August 3, 2016, 6:51am UTC](https://forums.unrealengine.com/t/problems-spawning-an-actor-in-c-for-use-in-the-editor/365962/1 "2016-08-03T06:51:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rantrod](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rantrod](https://forums.unrealengine.com/u/rantrod)\
**Post date:** [August 3, 2016, 9:04pm UTC](https://forums.unrealengine.com/t/problems-spawning-an-actor-in-c-for-use-in-the-editor/365962/2 "2016-08-03T21:04:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_67d829db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_67d829db](https://forums.unrealengine.com/u/anonymous_user_67d829db)\
**Post date:** [August 4, 2016, 3:13am UTC](https://forums.unrealengine.com/t/problems-spawning-an-actor-in-c-for-use-in-the-editor/365962/3 "2016-08-04T03:13:13Z")

</div>

- 
  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.

---

<div class="post-metadata">

**Author:** ![rantrod](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rantrod](https://forums.unrealengine.com/u/rantrod)\
**Post date:** [August 4, 2016, 6:40am UTC](https://forums.unrealengine.com/t/problems-spawning-an-actor-in-c-for-use-in-the-editor/365962/4 "2016-08-04T06:40:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_67d829db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_67d829db](https://forums.unrealengine.com/u/anonymous_user_67d829db)\
**Post date:** [August 4, 2016, 7:05pm UTC](https://forums.unrealengine.com/t/problems-spawning-an-actor-in-c-for-use-in-the-editor/365962/5 "2016-08-04T19:05:00Z")

</div>

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 :-(.
