0 votes

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

asked Feb 25, 2018 in Engine by GunPoint (395 points)

1 Answer

0 votes
Best answer

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.

answered Feb 25, 2018 by kidscancode (17,770 points)
selected Feb 25, 2018 by GunPoint

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!");

I have no idea about what this could mean...

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

In 2.1, you would use get_polygon(). 3.0 uses member variables. See http://docs.godotengine.org/en/latest/classes/class_collisionpolygon2d.html#member-variables

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

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

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

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

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
convex partition failed!

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.