Your code here does work properly:
[code:3gvj8dlq]+ System: On collision between Green (Pick) and Blue (Pick)
-> Output: Add 1 to 'hitCnt'
-> Output: Set text to Output.Value('hitCnt') & " : (" & Green.UID & "," & Blue.UID & ")"[/code:3gvj8dlq]
The reason that it's not triggering a collision consistently is that the Ball Behavior is performing it's own collision check and bouncing the balls away from each other before the sprites themselves can overlap. On Collision checks for overlap between two sprites, so if they're never actually overlapping then On Collision won't trigger.
Turn off Solid attribute for the balls and you will see that it's working and the UIDs are being picked properly.
The reason that it works sometimes
is that it's possible that timedelta is allowing the balls to move slightly closer to each other than they normally would before being bounced away, and on the next frame they are still overlapping and trigger On Collision.
You can get around this collision problem in a few different ways:
1. Don't use Ball Behavior. Physics Behavior can register "collisions" without having sprites overlap, and as a bonus you will get more accurate angle changes when objects collide.
2. Do use Ball Behavior, but try one of the following:
[*:3gvj8dlq] Turn off Solid for the ball sprites and code in your own bouncing events to change the angles of the balls when they hit each other.[/*:m:3gvj8dlq]
[*:3gvj8dlq] Add a separate, non-solid detector object to the ball (using Containers) that is slightly bigger than the ball. Use that for your On Collision event so that you can pick up the UID of the object the ball is colliding with. Like so: [/*:m:3gvj8dlq][/list:u:3gvj8dlq]
Hope this helps.