"Unable to iterate on object of type Object"... does this makes sense?

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

I have a system that auto-detects how many nodes with the same starting name are, and its adding the collision polygons in a navpolyinstance. While iterating i get this error

Unable to iterate on object of type Object

My script

for i in range(clicks):
	var col_polygon = get_node("object" + str(clicks)).get_node("CollisionPolygon2D")
	var new_poly = PoolVector2Array();
	for vector in col_polygon:
		new_poly.append(vector + get_node("object" + str(clicks)).get_position())

The clicks variable adds 1 to itself when a button is pressed.
The object node is an instanced scene which contains a collisionpolygon2d

:bust_in_silhouette: Reply From: kidscancode

You can’t iterate a CollisionPolygon2D, which is what the col_polygon variable is equal to after the get_node().

I think you want the object’s polygon, which would be:

var col_polygon = get_node("object" + str(clicks)).get_node("CollisionPolygon2D").polygon

The polygon property returns a PoolVector2Array which you can iterate.

See CollisionPolygon2D for details.

Oh yes, thats right… thank you… also, do you know what means “convex partition failed”. I get this message sometimes in the output and the navigation messes up
After searching through Godot’s code, i found this

TriangulatorPartition tpart;
if (tpart.ConvexPartition_HM(&in_poly, &out_poly) == 0) { //failed!
	print_line("convex partition failed!");
	return;
}

I have no idea about what this could mean…

GunPoint | 2018-02-25 20:37

and BTW, in Godot 3 its get_node("CollisionPolygon2D").get_polygon() instead of just polygon

GunPoint | 2018-02-25 20:44

In 2.1, you would use get_polygon(). 3.0 uses member variables. See CollisionPolygon2D — Godot Engine (latest) documentation in English

kidscancode | 2018-02-25 22:06

“convex partition failed” means the engine is having trouble partitioning your polygon. It could mean one of the vertices is badly placed.

kidscancode | 2018-02-25 22:07

Huh, weird… i use 3.0 stable, when i do get_polygon() it works, when i do polygon it crashes

GunPoint | 2018-02-26 14:11

Do you get an error when it crashes? Those should be equivalent.

kidscancode | 2018-02-26 16:46

Oh, no something else has caused the game to crash… my bad

GunPoint | 2018-02-26 18:22

And i really don’t know why i get the “convex partition failed” message. All vertices are in the right place, im sure about that (i use pixel snap). It messes up the navigation and i dont know why! The first collision the player touches works normal, but then i get this message and it basically deletes other collision polygons…
Thats what the console says:

ERROR: SelfList::List::~List: Condition ’ _first != 0 ’ is true.
At: c:\projects\godot-builds\godot\core\self_list.h:100
convex partition failed!

GunPoint | 2018-02-26 18:28