Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  'ObiCollider' does not contain a definition for 'idToCollider'
#1
Hello,

I want to realize that after I shoot water through Unity, I count the number of particles of water that fall on the floor. However, the script has failed to resolve the error 'ObiCollider' does not contain a definition for 'idToCollider'.

My Obi Fluid Version is 5.6.0.

Can someone help me?

Thank you.
Reply
#2
Hi,

"idToCollider" was removed in 5.0. See the manual for details on how to do this, and an example on how to retrieve the collider involved in a contact.
http://obi.virtualmethodstudio.com/tutor...sions.html
Reply
#3
(22-10-2020, 03:26 PM)josemendez Wrote: Hi,

"idToCollider" was removed in 5.0. See the manual for details on how to do this, and an example on how to retrieve the collider involved in a contact.
http://obi.virtualmethodstudio.com/tutor...sions.html


I'll do as you told me.

Thank you so much for your quick answer!
Reply
#4
I followed the example, but It still doesn't notice a collision and I think It's counting the number of just particles coming out of the emitter. Another solution I have in mind is to lower the version of Obi Fluid, is there a way to lower the version of Obi Fluid?
Reply
#5
(23-10-2020, 11:35 AM)dabinzzang Wrote: I followed the example, but It still doesn't notice a collision and I think It's counting the number of just particles coming out of the emitter. Another solution I have in mind is to lower the version of Obi Fluid, is there a way to lower the version of Obi Fluid?

Works just fine for me, can you share the exact code you're using?
Reply
#6
(23-10-2020, 11:39 AM)josemendez Wrote: Works just fine for me, can you share the exact code you're using?
Code:
[RequireComponent(typeof(ObiSolver))]
public class CollisionEventHandler : MonoBehaviour
{

    ObiSolver solver;
    public int counter = 0;
    public Collider targetCollider = null;
    Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;

    HashSet<int> particles = new HashSet<int>();

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

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

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

    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        HashSet<int> currentParticles = new HashSet<int>();

        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.00001)
            {
                ObiColliderBase collider = world.colliderHandles[contact.other].owner;
                if (collider != null)
                {
                    currentParticles.Add(contact.particle);
                }
            }
        }

        Debug.Log(currentParticles.Count);
        particles.ExceptWith(currentParticles);
        counter += particles.Count;
        particles = currentParticles;
    }
}

Here you are. Thank you very much.
Reply
#7
(23-10-2020, 11:53 AM)dabinzzang Wrote:
Code:
[RequireComponent(typeof(ObiSolver))]
public class CollisionEventHandler : MonoBehaviour
{

    ObiSolver solver;
    public int counter = 0;
    public Collider targetCollider = null;
    Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;

    HashSet<int> particles = new HashSet<int>();

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

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

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

    void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        HashSet<int> currentParticles = new HashSet<int>();

        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.00001)
            {
                ObiColliderBase collider = world.colliderHandles[contact.other].owner;
                if (collider != null)
                {
                    currentParticles.Add(contact.particle);
                }
            }
        }

        Debug.Log(currentParticles.Count);
        particles.ExceptWith(currentParticles);
        counter += particles.Count;
        particles = currentParticles;
    }
}

Here you are. Thank you very much.

What this does is it counts the amount of new particle hits any collider has experienced (cumulative over time), and stores that in the "counter" variable. Works perfectly fine. Note that the number logged to the console is the total amount of current contacts with *any* collider or trigger in the scene, the "targetCollider" variable is completely unused in the script.

What is it that you want to count?
Reply
#8
(23-10-2020, 12:10 PM)josemendez Wrote: What this does is it counts the amount of new particle hits any collider has experienced (cumulative over time), and stores that in the "counter" variable. Works perfectly fine. Note that the number logged to the console is the total amount of current contacts with *any* collider or trigger in the scene, the "targetCollider" variable is completely unused in the script.

What is it that you want to count?

First of all, thank you very much for your quick and accurate response.

My problem is that the number of particles released from the emitter is counting from before they hit the ground(here ground is designed as targetcollider).
I want to know the number of water particles that hit the ground.

and, i have a question, "the "targetCollider" variable is completely unused in the script." what does it mean?
Reply
#9
(24-10-2020, 06:47 AM)dabinzzang Wrote: First of all, thank you very much for your quick and accurate response.

My problem is that the number of particles released from the emitter is counting from before they hit the ground(here ground is designed as targetcollider).
I want to know the number of water particles that hit the ground.

That "hit" the ground, or that "stay" on the ground? when a particle is no longer in contact with the ground, does it still count?

(24-10-2020, 06:47 AM)dabinzzang Wrote: and, i have a question, "the "targetCollider" variable is completely unused in the script." what does it mean?

It means the variable is declared, as if it was going to be used for something, but then it is not used at all in the script. It is not written to or read from, it just exists but it does nothing. It looks like you wanted to filter out collisions so that only those against a given collider were considered, but as the code is currently written, any collision with any collider is counted. I assume you copy-pasted code from several sources in a "collage" fashion, as there's other bits in the code that make little sense. Putting together code that you don't understand is a recipe for problems. Confundido
Reply