+3 votes

Newbie question.. I tried few ways and looks like I did not manage it to work..
Lets say I need Add my objects to an array and wan t manipulate them straight from array. (and not to fetch them temporary to Spatial variable..)

Var myarray:Spatial = [] # no..?
Var my
array= []:Spatial # no..?
Var myarray= [:Spatial] # no..?
Var my
array= [] as Spatial [] #????...not tested..

Or is it even possible

asked Apr 17, 2019 in Engine by Godotmus (35 points)

1 Answer

+4 votes
Best answer

Type hints can't be used with arrays. The Array container in Godot is a variant container. If you have a particular need for a single-typed array, there are the Pool*Array types.

You can still add Spatial objects to your array, you just can't specify that the array will only hold Spatials.

answered Apr 17, 2019 by kidscancode (16,546 points)
selected Apr 17, 2019 by Godotmus
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.