# GetInstanceCount() returns 1 after removing an instance

**URL:** <https://forums.unrealengine.com/t/getinstancecount-returns-1-after-removing-an-instance/1725771>\
**Category:** C++\
**Tags:** Hierarchical-Instanced-Static-Mesh, instance, unreal-engine, Instanced-Mesh, saving, remove, instances, staticmesh, question, CPP\
**Created:** [March 2, 2024, 9:40pm UTC](https://forums.unrealengine.com/t/getinstancecount-returns-1-after-removing-an-instance/1725771 "2024-03-02T21:40:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_untextured](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@The\_untextured](https://forums.unrealengine.com/u/The_untextured)\
**Post date:** [March 2, 2024, 9:40pm UTC](https://forums.unrealengine.com/t/getinstancecount-returns-1-after-removing-an-instance/1725771/1 "2024-03-02T21:40:08Z")

</div>

I am having a majour problem.

I have a Hierarchical Instanced Static Mesh Component which can be modified during runtime and can be saved/loaded. When I remove an instance, if I save the game soon after, only the instance which I just removed gets saved. (All the rest get discarded) I checked and it is not a problem in my code. GetInstanceCount() returns 1 for some reason.

I tried looking at the UE source code but I can’t seem to find the problem.

Here is my save code:

```cpp
for (int32 in = 0; in < i->GetInstanceCount(); in++) {
    FInstanceData d;
    i->GetInstanceTransform(in, d.Transform, true);
    d.Variation = i->Variation;
    OutData[id] = d;
    id++;
}

```

Where i is of kind `class UHISM : public UHierarchicalInstancedStaticMeshComponent` object pointer (A custom class)

Anybody has any idea as to why this happens?
