Download

UInstancedStaticMeshComponent does not showing static meshes

Hello
For a few days I am trying to solve one problem with using UInstancedStaticMeshComponent. I have created class based on AActor.
Add as property some variables:


UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
class UInstancedStaticMeshComponent*    InstancedArrowsMesh;
UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category = "Arrows")
int32    CountArrows;


In the constructor I’ve write the next strings:


InstancedArrowsMesh = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("InstancedArrowsMesh"));
    InstancedArrowsMesh->AttachToComponent(StaticMesh, FAttachmentTransformRules::KeepRelativeTransform);
    InstancedArrowsMesh->RegisterComponent();
    InstancedArrowsMesh->InstancingRandomSeed = 26425;
    InstancedArrowsMesh->SetMobility(EComponentMobility::Movable);
    CountArrows = 3;

At the function BeginPlay I have write the next strings:


InstancedArrowsMesh->ClearInstances();

   const int32 nMaxArrowCount = ArrowSpawnArray.Num();

    for (int nArrowIdx = 0; nArrowIdx < CountArrows; nArrowIdx++)
    {
        if (nArrowIdx < nMaxArrowCount)
        {
            USceneComponent* sceneComp = ArrowSpawnArray[nArrowIdx];
            if (sceneComp)
            {
                FTransform    instanceTransform = sceneComp->GetRelativeTransform();
                InstancedArrowsMesh->AddInstance(instanceTransform);
            }
        }
        else
        {
            break;
        }
    }

After that, I’ve created blueprint class based on my C++ class.
If I am adding that blueprint class on sceen directly (using drag’n’drop) everthing is fine. After launch the game I see my object with Instanced Static Meshes objects. But if I spawn my object dynamicly using GetWorld()->SpawnActor(…) function I am seeing my object too, but without any instanced static meshes within.
What is wrong? What I have missed?
When I debugged this feature, everthing is fine, BeginPlay function is called and my Instanced Static Meshes added successfully. I have no idea, what I have missed

Please help me with it !!!

Spawned_by_C.pngIn first case you see Bow Arrows (Instanced Static Meshes) in second case the Quiver is empty. There is only defferent in method of spawning.

Can anybody help me solving this issue?