0 votes

So I get this error every frame:

Index p_contact_idx out of size (body->contact_count)

The engine says the culprit is the line

if state.get_contact_collider_object(i):

I do have multiple contacts reported. The amount doesn't apparently even matter. Is this an engine bug?

My version is stable. I tried with 2.1.4 too, which funnily says "Invalid ID" as first line before it starts spouting that error.

The most fun thing, though? The code definitely works. It just gives errors as a bonus.

func _integrate_forces(state):
for i in range(get_max_contacts_reported()):
    if state.get_contact_collider_object(i):
        if state.get_contact_collider_object(i).is_in_group("sparkobject"):
            sparksposition = state.get_contact_local_pos(i)
in Engine by (15 points)
edited by

1 Answer

+1 vote
Best answer

This is description of get_max_contacts_reported()

int get_max_contacts_reported() const

Return the maximum contacts that can be reported. See set_max_contacts_reported().

you may set it as like 10.
the number of contacted objects might be less than 10.
but you made loop to get collider object 0~9.

by (9,784 points)
selected by

Yes, well I wanted to go through them, but I should of course be using get_colliding_bodies().size(), I need a new brain.

And that if was supposed to check for null, it did earlier.
But I still get the error. Though now it happens on the is_in_group() part and only once every time when bodies stop touching.

func _integrate_forces(state):
    for i in range(get_colliding_bodies().size()):
        if state.get_contact_collider_object(i) != null:
            if state.get_contact_collider_object(i).is_in_group("sparkobject"):
                sparksposition = state.get_contact_local_pos(i)

Well, I learned something about weakref and stuff. I moved lot of checks over to the signal. Now I still get the same error, but only when thing touches multiple things... The culprit is now sparksposition = state.get_contact_local_pos(sparkbody)

func _integrate_forces(state):
if bodylist != null && sparkbody != null && wr.get_ref() && state.get_contact_count() > 0:
    sparksposition = state.get_contact_local_pos(sparkbody)

func _on_Link1_body_enter( body ):
    if body.is_in_group("sparkobject"):
        wr = weakref(body)
        bodylist = get_colliding_bodies()
        for i in bodylist:
            if !wr.get_ref():
            elif body.is_in_group("sparkobject"):
                sparkbody = bodylist.find(body)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.