# Premade rooms picking random locations

**URL:** <https://forums.unrealengine.com/t/premade-rooms-picking-random-locations/456357>\
**Category:** Blueprint\
**Tags:** randomize-array, unreal-engine, Blueprint, question\
**Created:** [October 3, 2019, 8:16am UTC](https://forums.unrealengine.com/t/premade-rooms-picking-random-locations/456357 "2019-10-03T08:16:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flame](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Flame](https://forums.unrealengine.com/u/Flame)\
**Post date:** [October 3, 2019, 8:16am UTC](https://forums.unrealengine.com/t/premade-rooms-picking-random-locations/456357/1 "2019-10-03T08:16:28Z")

</div>

hi everyone. I’m trying to create a sort of random placing of rooms in my game, but i’m probably making something stupid. If i don’t use for loops and just try one random from the list, it works, but using for loops or doing 2 in a sequence keeps throwing me these errors(from my debugging i guess it means the results from the array are null)  
i have currently 3 levels in the level array and 3 possible random spots(those are actors picked in the persistent level) where each room could spawn(so i am trying to use a for loop to iterate through each one of the levels in the array and choose a random spot.

another thing i noticed, is that no matter what when using the random integer, i never get my index 0 result from the array.  
Hoping some guidance here. thank you very much.

 ![289042-image-9.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/6/b0681e806a603c8c45c8e8079a370687cc21208f.png)

 ![289043-image-8.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/d/b/4db5541d373682b97384e396124d488103cd870d.png)

---

<div class="post-metadata">

**Author:** ![BlueMind\_Studio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BlueMind\_Studio](https://forums.unrealengine.com/u/BlueMind_Studio)\
**Post date:** [October 3, 2019, 8:53am UTC](https://forums.unrealengine.com/t/premade-rooms-picking-random-locations/456357/2 "2019-10-03T08:53:58Z")

</div>

You have Not connected your -1 Node to the lastIndex of forLoop and to the max of randomInteger

---

<div class="post-metadata">

**Author:** ![Flame](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Flame](https://forums.unrealengine.com/u/Flame)\
**Post date:** [October 3, 2019, 3:29pm UTC](https://forums.unrealengine.com/t/premade-rooms-picking-random-locations/456357/3 "2019-10-03T15:29:21Z")

</div>

thank you for your reply/ I was under the impression if I use a “length” instead of the last index(as i was not using last index) i don’t need to do the -1.

it throws out less errors, but still gives me this error

Play in editor start time for /Game/Levels/UEDPIE\_0\_Proceadural\_Grid\_Persistent\_Level 0.465  
Blueprint Runtime Error: “Accessed None trying to read property CallFunc\_CreateInstance\_ReturnValue”. Blueprint: Proceadural\_Grid\_Persistent\_Level Function: Execute Ubergraph Proceadural Grid Persistent Level Graph: EventGraph Node: Set  
Blueprint Runtime Error: “Attempted to assign to None”. Blueprint: Proceadural\_Grid\_Persistent\_Level Function: Execute Ubergraph Proceadural Grid Persistent Level Graph: EventGraph Node: Set  
Blueprint Runtime Error: “Accessed None trying to read property CallFunc\_CreateInstance\_ReturnValue”. Blueprint: Proceadural\_Grid\_Persistent\_Level Function: Execute Ubergraph Proceadural Grid Persistent Level Graph: EventGraph Node: Set bShouldBeLoaded  
Blueprint Runtime Error: “Accessed None trying to read property CallFunc\_CreateInstance\_ReturnValue”. Blueprint: Proceadural\_Grid\_Persistent\_Level Function: Execute Ubergraph Proceadural Grid Persistent Level Graph: EventGraph Node: Set bShouldBeVisible

---

<div class="post-metadata">

**Author:** ![BlueMind\_Studio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BlueMind\_Studio](https://forums.unrealengine.com/u/BlueMind_Studio)\
**Post date:** [October 4, 2019, 5:08am UTC](https://forums.unrealengine.com/t/premade-rooms-picking-random-locations/456357/4 "2019-10-04T05:08:08Z")

</div>

Thats Strange. When i’m Not wrong, lets say in an Array with 5 Elements length should Print you 5 and lastIndex 4. So you should use -1 or lastIndex. But you can Doublecheck with a Printstring.

Add a isValid after the createInstance and in the Fail Node Connect Something Like a Printstring and Set a Breakpoint. When it Hits that Error, Check your variables in the BP (ints/Index/Array). If you don’t find a Thing temporarily disable the random Logic and Just Check in the forLoop that EVERY Level in your Array works.
