Objects Collider - "OnCollisionEnter" like

Hello everyone :slight_smile:

I have a very simple question, but wich I think is a big deal for Grasshopper ^^
It has certainly something to do with data stream, recursive etc…

I made this little exemple, but in my other project there is incoming networking involved but wasn’t an easy setup like that one to show.

The fact is I would to be able to detect when an object enter another object but only once !
So a little idea would be to check in the stream of bools when there is :

  • a switch from False to True would be OnCollisionEnter()
  • a switch from True to False would be OnCollisionExit()

Maybe sombody already made a script to get this kind of behaviour.
true ( here : i = i + 1 )

The file : Collider-Question_v1.gh (12.6 KB)

A little image to complete the post :


The most straightforward way would be to place a Data Recorder component between your boolean and the counter, which gives you a stream of data across solutions that you require. Then just check for the last two values in that stream to detect an “event”:

You could use global or sticky variables in Python to replicate this behaviour and automatically discard old values (see this previous thread), I don’t think that’s directly possible using C#.

Collider-Question_v1.gh (13.2 KB)


1 Like

Yup, the Data Recorder is the only way in vanilla Grasshopper to carry data over from one solution to the next. You’d have to make it flexible enough so that when there is only one solution (for example just after you open the file) it still works and generates sufficient data so that the next iteration can proceed as expected.

1 Like

Thank you qythium and David,

That solution of qythium is just working fine with this little exemple I sent.

But when I start to try it with the actual project is a nightmare.
Things are working fine like 10 seconds and then Grasshopper start to slow a lot even moving in the interface is being kind of hard and even when I reset the data Recorder’s cache.
I also tried with the Python improved data recorder. I’m getting the exact same result.

About the setup :
I have Unity engine that send a Boolean (0 or 1) through the network (UDP).
Grasshopper side, I’m getting it with gHowl.
Since the bool is coming through the network, is a data stream which means a lot of falses… and then switch to true and then go to false again.

So exactly like in the Collider example, but is happening in an incoming stream and not internally into grasshopper.

As you said David, data recorder is the only way in the vanilla version of Grasshopper.
But the last months I really liked to add features to grasshopper with C# custom components.
This flexibility makes Grasshopper just beautiful, so I don’t mind to use a C# solution.

If you have some c# exemple to achieve this in your giant personal toolbox of codes would be awesome to test it. :slight_smile: