# PCG Loop Number of Iterrations

**URL:** <https://forums.unrealengine.com/t/pcg-loop-number-of-iterrations/2339937>\
**Category:** Editor Scripting\
**Tags:** unreal-engine, procedural, question, Blueprint\
**Created:** [February 17, 2025, 7:55pm UTC](https://forums.unrealengine.com/t/pcg-loop-number-of-iterrations/2339937 "2025-02-17T19:55:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartiniBomb](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/martinibomb/32/914455_2.png) [@MartiniBomb](https://forums.unrealengine.com/u/MartiniBomb)\
**Post date:** [February 17, 2025, 7:55pm UTC](https://forums.unrealengine.com/t/pcg-loop-number-of-iterrations/2339937/1 "2025-02-17T19:55:34Z")

</div>

Hi I’m wondering if there’s any way to get the number of loop iterations of a PCG loop and/or sum the value of attributes in an array. For example I’m trying to do something like this pseudocode:

**weights** = Array of float values  
**sum** = sum of the values in **weights**  
**normalizedWeights** = new array  
for each **weight** in **weights** {  
– **normalizedWeights** [i] = **wights** [i] / **sum**  
}  
return **normalizedWeights**

or even just

**meshes** = array _of_ arrays _of_ meshes  
for each **array** in **meshes** {  
– **max** = (index + 1) \* (1 / numberOfItterations)  
– **min** = (index) \* (1 / numberOfItterations)  
– spawn all meshes in **array** when density is between **min** and **max**  
}

Is anything like these possible in unreal pcg? It seems like there should be but I can’t seem to make it work. I’m pretty sure I’m missing something here so i would love some help!

---

<div class="post-metadata">

**Author:** ![MartiniBomb](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/martinibomb/32/914455_2.png) [@MartiniBomb](https://forums.unrealengine.com/u/MartiniBomb)\
**Post date:** [February 17, 2025, 9:00pm UTC](https://forums.unrealengine.com/t/pcg-loop-number-of-iterrations/2339937/2 "2025-02-17T21:00:15Z")

</div>

Just solved this with a little experimentation, turns out learning a little bit about the inspect panel in the editor is useful. But two “Get Entries Count” nodes can get the number of entries which can get then be passed to the loop, and there’s a sum node if you need a sum!

See the pic below for my implementation, where the “num” input to the loop is the number of times the loop will run. This could then be packaged into another subgraph to clean things up because the inputs to the double entries chain, and the “Meshes” input are the same. Hope this helps someone!

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/b/bbb6ba5959e0566af150ea74e8397e91ad24a8a4.png)

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [March 19, 2025, 9:00pm UTC](https://forums.unrealengine.com/t/pcg-loop-number-of-iterrations/2339937/3 "2025-03-19T21:00:58Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
