How do I instance an object from an array

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ultragamer229

I was trying to create an pattern in Godot that has 3 scene patterns, so I’ve created the array with preload(), and with a function i’ve putted this code to start the ramdom select of the pattern:

var new_pattern = patterns[randi()%patterns.size()].instance()

but how these patterns are platforms I’ve put this code:

`new_pattern.position.x = initialPatterns.back().position.x + 1024`

so I’ve received this error:

Invalid get Index ‘position’ (on Base: PackedScene)

:bust_in_silhouette: Reply From: Inces

initialPatterns is an array of paccked scenes, so they don’t have position at that state. How do You want to randomize position ?