disable collider in children doesnt work

im able to enable them but disabling them doesnt do anything. i check with debug and it shows i accessed them but disable collider doesnt work. when i try to do istrigger false it works which means that collider also works but disable collider doesnt.

public void stop_laser()
{
for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).GetComponent().enabled = false;
}
gameObject.SetActive(false);
}

It works perfectly fine, you’re doing something else wrong here as this is such a basic thing to do.

When you disable a collider, what you’re actually doing is removing everything from the physics-side of things. It won’t continue to work, there’s nothing there.

Note that one of the colliders cannot be disabled and you’ll see that there’s no disable check-box in the inspector; that’s the CompositeCollider2D.

If you run the code above, you’ll see the colliders have their check-box unchecked but if not, your code isn’t running or isn’t working on the correct thing. Note that if you look at any of the collider in question in the inspector and open the “Info” foldout, you’ll see how many shapes it has created. A disabled collider will always have zero shapes in the physics engine.

Also, your code doesn’t really make sense. If you deactivate the GameObject, everything is disabled anyway so what’s the point in explicitly disabling the colliders?

All of the above comments assume you’ve debugged this before coming to the forums to check it’s running and working on the correct things. I presume you’ve done this.

BTW, here’s how to post code on the forums: Using code tags properly

hi i tried to make a game object that doesnt immidetly starts its trigger detection thats why i also have disablegameobject.
i think you didnt understand my point/ the problem is that i want to disable the colliders. i saw from the debug that i do access the children gameobject and also for example istrigger on their collider worked but not disable the collider

I’m not following you here. If your GameObject is deactivated, none of the colliders will work anyway nor will anything else on it.

I followed that just fine.

Look at what I typed previously. Verify that they are being disabled.

but i wrote it before disabling the gameobject. also when i deleted that line it doesnt work

You are trying to convince me that physics is broken at a basic level and that just isn’t the case.

You need to verify that they are being disabled as I indicated above twice now. Please explain how you’re determining that it isn’t working.

I’m trying to figure out what the confusion is here with very little info. If you want me to help, please provide some more info showing what you’re doing. All I have is the plain text script above.

i checked from inspector that its still enabled. i also checked from there that i was able to change methods in collider component like istrigger

Did you verify that the code above runs then? A component not being disabled means the code above isn’t running or running on the wrong thing.

Place a Debug.Log("Disabling " + gameObject.name) as the first line.

I’ve found a similar problem and here’s how i solved it:
create a variable on your script attached to the gameObject calling the collider2d as a collider.

ex:
public Collider2D myGameObjectCollider;

then you can call enable = false or true. But first drag the collider into the slot for it in the inspector.

Sorry but I don’t see what this has to do with the OPs post.

Yes, you can create public fields that explicitly reference things such as components but that’s not the above problem as reported.