Obi Official Forum
Help Simple Collision Debug Log - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: Help Simple Collision Debug Log (/thread-4586.html)



Simple Collision Debug Log - PortableAnswers - 25-01-2026

Hello,

I am able to make fluid collide with 3D objects using the Obi Colliders, but I have yet to figure out how to get any data back from the collision itself. 
Even just a Debug.Log("Foo") would be enough to get me in the right direction.

Here's the code snippet in the documentation that I first started messing around with:
Code:
ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

Any step-by-step instructions would be great. Thanks!


RE: Simple Collision Debug Log - josemendez - 26-01-2026

(25-01-2026, 05:38 PM)PortableAnswers Wrote: Here's the code snippet in the documentation that I first started messing around with:
Code:
ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

Any step-by-step instructions would be great. Thanks!

Hi!

Assuming you're just using that one line of code, all it does is retrieve a reference to a collider. You're not subscribing to the contact callback event, and not checking any contacts. Try the full snippet:

Code:
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class CollisionEventHandler : MonoBehaviour {

    ObiSolver solver;

    void Awake(){
        solver = GetComponent<ObiSolver>();
    }

    void OnEnable () {
        solver.OnCollision += Solver_OnCollision;
    }

    void OnDisable(){
        solver.OnCollision -= Solver_OnCollision;
    }

    void Solver_OnCollision (object sender, ObiNativeContactList e)
    {
        var world = ObiColliderWorld.GetInstance();

        // just iterate over all contacts in the current frame:
        foreach (Oni.Contact contact in e)
        {
            // if this one is an actual collision:
            if (contact.distance < 0.01)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;
                if (col != null)
                {
                    // do something with the collider.
                        Debug.Log("Foo");
                }
            }
        }
    }

}

let me know if you need further help,

kind regards