# Instanced Static Mesh Not Appearing

**URL:** <https://forums.unrealengine.com/t/instanced-static-mesh-not-appearing/429099>\
**Category:** Asset Creation\
**Tags:** spawning, Instanced-Mesh, unreal-engine, question\
**Created:** [July 10, 2018, 2:43pm UTC](https://forums.unrealengine.com/t/instanced-static-mesh-not-appearing/429099 "2018-07-10T14:43:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WarpSpider833](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@WarpSpider833](https://forums.unrealengine.com/u/WarpSpider833)\
**Post date:** [July 10, 2018, 2:43pm UTC](https://forums.unrealengine.com/t/instanced-static-mesh-not-appearing/429099/1 "2018-07-10T14:43:17Z")

</div>

I’m trying to create an instanced static mesh, and I’m not sure I’m doing it right. The following code is in a ‘Creator’ component that is supposed to spawn MyObject at the origin…

Creator.h

```
UPROPERTY(EditAnywhere)
		TSubclassOf<class AActor> ToSpawn; // Set this to MyObject

UPROPERTY(EditAnywhere)
		UStaticMesh* SuperMesh; // Set this to the mesh

```

Creator.cpp

```
// Other things

UInstancedStaticMeshComponent *ISMComp = NewObject<UInstancedStaticMeshComponent>(ToSpawn);

UWorld* const World = GetWorld();
	if (!World) return;

ISMComp->RegisterComponent();
	ISMComp->SetStaticMesh(SuperMesh);
	ISMComp->SetFlags(RF_Transactional);

FRotator rotator = FRotator(0.f, 0.f, 0.f);
	FVector spawnLocation = FVector(0.f, 0.f, 0.f);
	FActorSpawnParameters spawnParams;

AMyObject* Obj = World->SpawnActor<AMyObject>(ToSpawn, spawnLocation, rotator, spawnParams);

Obj->AddInstanceComponent(ISMComp);

```

Anyway, it compiles, but no object appears…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6789817d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6789817d](https://forums.unrealengine.com/u/anonymous_user_6789817d)\
**Post date:** [July 10, 2018, 8:19pm UTC](https://forums.unrealengine.com/t/instanced-static-mesh-not-appearing/429099/2 "2018-07-10T20:19:22Z")

</div>

You need to create and register your component _after_ spawning the actor you’re trying to attach it to. You’ll also need to pass in “Obj” instead of “ToSpawn” to the call to “NewObject” when creating the component.

---

<div class="post-metadata">

**Author:** ![WarpSpider833](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@WarpSpider833](https://forums.unrealengine.com/u/WarpSpider833)\
**Post date:** [July 11, 2018, 10:46am UTC](https://forums.unrealengine.com/t/instanced-static-mesh-not-appearing/429099/3 "2018-07-11T10:46:03Z")

</div>

Okay, so I’ve rewritten the code as follows:

```
// Spawn Parameters

AMyObject* Obj = World->SpawnActor<AMyObject>(ToSpawn, spawnLocation, rotator, spawnParams);

ISMComp = NewObject<UInstancedStaticMeshComponent>(Obj);

ISMComp->RegisterComponent();
ISMComp->SetStaticMesh(SuperMesh);
Obj->AddInstanceComponent(ISMComp);

```

This compiles, but the mesh does not appear in game. If I find the actor while playing in the world outliner and click on the component “instancedStaticMeshComponent\_0”, the ‘Instances’ section says there are ‘0 array elements’. If I add one there, the mesh appears… this makes me think I’m missing something.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6789817d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6789817d](https://forums.unrealengine.com/u/anonymous_user_6789817d)\
**Post date:** [July 11, 2018, 2:45pm UTC](https://forums.unrealengine.com/t/instanced-static-mesh-not-appearing/429099/4 "2018-07-11T14:45:30Z")

</div>

Oh! That’s because you haven’t told it to add any instances. Now that your component is created, you can do something like this:

```
FTransform InstanceTransform;
InstanceTransform.SetLocation(FVector::ZeroVector);
InstanceTransform.SetRotation(FQuat::Identity);

ISMComp->AddInstance(InstanceTransform);

```
