Skip to content

Instantly share code, notes, and snippets.

@levilansing
Created January 2, 2024 22:45
Show Gist options
  • Save levilansing/bcb4109b429ff519e0301b35c49cc176 to your computer and use it in GitHub Desktop.
Save levilansing/bcb4109b429ff519e0301b35c49cc176 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using UnityEngine;
public static class ColliderTwiddler {
static List<Collider> colliders = new();
/**
* This is a hack to force the colliders to trigger OnTriggerEnter/etc.
* Call this after instantiating an object or adding a rigidbody to it.
*/
public static void Twiddle(GameObject gameObject) {
colliders.Clear();
gameObject.GetComponentsInChildren(colliders);
foreach (Collider collider in colliders) {
bool val = collider.enabled;
if (val) {
collider.enabled = false;
collider.enabled = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment