My cycle "for" is not working!

Hey. I am creating a cycle that must pass through the array and create Astor, but he does not want to work! I served on the function and the input BeginPlay parametn I feed an array of structures that con Also I look how many elements in a loop through and it shows the correct amount of (3), and the cycle goes first element and stops. What could be the problem? Thank you. P.S.
A Blueprint everything works fine, but there is no C ++ :frowning:

TArray<AStorageItem*> UStorageComponent::CreateItems(TArray<FST_BeginItemInfo> &Structure)
{
	TArray<AStorageItem*> CreatedItems; 
	if (Structure.Num() > 0)
	{
		for (int32 i = 0; Structure.Num() > i; i++)
		{
			GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::FromInt(i));
			GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::FromInt(Structure.Num()));
			if (CheckIftemCanBeCreated(Structure[i].ItemClass, Structure[i].Count))
			{
				UWorld* const World = GetWorld();
				if (World)
				{
					FActorSpawnParameters SpawnParams;
					SpawnParams.Owner = GetOwner();
					SpawnParams.Instigator = UGameplayStatics::GetPlayerPawn(this, 0);
					SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

					FVector SpawnLocation = FVector(0.f, 0.f, 0.f);
					FRotator SpawnRotation;
					SpawnRotation.Yaw = 0.f;
					SpawnRotation.Pitch = 0.f;
					SpawnRotation.Roll = 0.f;

					AStorageItem* ItemSpawn = World->SpawnActor<AStorageItem>(Structure[i].ItemClass, SpawnLocation, SpawnRotation, SpawnParams);
					AddItem(ItemSpawn, this);
					CreatedItems.Add(ItemSpawn);
					return CreatedItems;
				}
				return CreatedItems;
			}
		}
		return CreatedItems;
	}
	return CreatedItems;
}

Is there a chance of this function failing? < CheckIftemCanBeCreated(Structure[i].ItemClass, Structure[i].Count) >
It might be that < CheckIftemCanBeCreated > returns false the second time and so the spawning stops. It’s hard to understand your writing in the description.

No, not the problem. The fact is that after the cycle is AddOnScreenDebugMessage, which shows me the set number of cycles. The array element 2 is obtained cycle must show i = 1, but it shows i = 0. The cycle always takes place only 1 time.

It only runs once because of the return statements. If CheckIftemCanBeCreated is true then it will only run one time because it’s guaranteed to hit one of the “return CreatedItems;” lines. I suggest taking out the return lines inside of the for loop to allow it to add to the array as many times as possible before sending the array back out of the function.