playMaker

Author Topic: Global trigger events  (Read 4983 times)

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Global trigger events
« on: October 19, 2015, 04:35:27 PM »
I'm trying to have an object test how many other objects it is currently colliding with. Its collider is set to Is Trigger. The FSM starts with a couple of trigger 2D Event actions to catch exits and exits and then increments or decrements a count variable accordingly before returning to the Start to check for more.

It caught the first enter and the first exit and then stopped.

So instead, I tried using TRIGGER ENTER 2D and TRIGGER EXIT 2D as global events. Neither responded to anything. I've had this problem before, where these global events fail to register, and have never got them to work, but I previously resolved problems using the action level detection instead. What have I misunderstood about these global events, and what should I do? (Incidentally, I've never had a problem using custom global events.)


UPDATE: I got the global events to work. I forgot to put the 2d proxy component on the object running the test. However, now the trigger count is capturing WAY more enters than exits. It goes into thousands within a few seconds. Why might this be happening?

For clarity, I'm attaching a screenshot of the simple FSM.


UPDATE: Two things. (1) Discovered a glitch in one of the gameobjects which was (God knows how) continually sending trigger enters regardless of its relative position. All colliders were miles apart. I deleted it and replaced it with its identical prefab, and that issue stopped. The collision count is still failing, however, but it's overcounting by tens rather than thousands. Whatever that glitch was, it was obviously a Unity issue - which begs the question, how am I supposed to know whether Unity is at fault or I am? Any tips on troubleshooting common glitches would be useful, though perhaps off topic here. I still have no idea whether the problem that still remains is its fault or mine.

(2) I copied and pasted a piece of script to count triggers (working on the same principle, which I attached to the object I want to use it. At first, it had the same problem as the FSM, running the count into thousands. However, after I got rid of the glitchy object, it seems to be working - or more or less - at least close enough to require careful testing to make sure. BUT - the FSM is still running very high - a steady count to 70+ in a few seconds. I don't want to use the script - I want to stay within Playmaker, for all sorts of reasons. So my question is, is my FSM wrong, and if so how?
« Last Edit: October 20, 2015, 03:11:17 PM by cats00eye »

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Global trigger events
« Reply #1 on: October 21, 2015, 05:15:47 PM »
I'm just about ready to chuck this in. I must be the only person having this problem. If a basic thing like a trigger count function can't count triggers, either my function is profoundly wrong or there is no possibility of making anything sensible with these tools. Right now, I simply don't know which it is.

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
Re: Global trigger events
« Reply #2 on: October 21, 2015, 08:34:18 PM »
If I was doing what you were doing, I wouldn't use transitions the way you are.

I would probably just have a starting state called "Listener", with a "Trigger Event" action on it... that trigger event would connect to an increment count state, and then loop back into the listener.

A second "trigger event" action in the first state would go around the same loop for trigger exits

I don't know if that would actually work as I don't really have time to set a test scene, but you could try that implementation?

Out of interest, are you a 2d or 3d game?

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Global trigger events
« Reply #3 on: October 22, 2015, 10:44:09 AM »
Thanks very much for the reply. It's 2d, but more of an experiment than a game atm. I think I may have set it up using action level detection originally, but I'll try it the way you describe. But the script I was using, which I thought was working, is now not - so the problem is either the way Unity works (or doesn't) or the way I do (or don't). I think the difference between when the script works and when it doesn't is that in the test scene there are about nine or so tagged colliders and they're quite large, so there are multiple overlaps all over the place. It worked when the colliders were smaller. I will test out your suggestion on a few set-ups and see what happens. Thanks again.


UPDATE. Okay, I set up the simplest possible test scene. It has three small circular sprites and nothing else. The first - call it "watcher" - is the one checking for triggers: it has a collider set to its own size, and not set to "is trigger". Sprites 2 and 3 - tagged "enemy" - each have a collider with radius set to 9, substantially larger than the sprites themselves and these two colliders are set to "is trigger". There is no script on any of the 3 sprites other than the trigger checker, of which I'm attaching a screen shot. The "watcher" sprite is sitting inside both the colliders of the enemies.
Hit run: the triggercounter correctly shows a value of 2. But as soon as I drag the watcher sprite a little in the scene window, the triggercounter starts counting up and fast. This stops when the sprite leaves both enemy triggers, but the count obviously doesn't show zero as it should. It's like every frame of movement is triggering an enter event. Exit triggers seem to be normal, so far as I can judge. I tried the adding the trigger count script and it showed the exact same (incorrect) figure as the FSM. I reduced the enemy colliders to be their default size but the problem remains.
« Last Edit: October 22, 2015, 01:16:05 PM by cats00eye »

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Global trigger events
« Reply #4 on: October 22, 2015, 03:29:17 PM »
I think I should take this to the Unity2d forum since it doesn't really look like a Playmaker issue. (Though any input about what's going on would be more than welcome.)

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
Re: Global trigger events
« Reply #5 on: October 22, 2015, 09:17:18 PM »
when you say "drag the sprite" - is this with an in-game interaction, or via Unity control handles?

If it's the latter, my guess would be that when an object is moved in that way, rather than inside the game itself, Unity might well rebuild the physics system, which would cause objects inside the triggers to be redetected as having just entered.

I would try scripting a simple motion on your box (easily done with playmaker, but you could also just use normal C#/Unityscript if you prefered) and see if the problem still happens.

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Global trigger events
« Reply #6 on: October 23, 2015, 07:59:48 AM »
You're right. It counts too many triggerenters when the sprite is dragged in the scene window but not (in the very simple test scene) when moved in-game. The scene dragging thing was a red herring because it looked exactly like what was happening in my actual scene (in-game). And so my problem with my actual scene still remains. I'm really stumped.

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
Re: Global trigger events
« Reply #7 on: October 23, 2015, 09:58:27 PM »
Not sure I understand what the problem is any more? I thought it was working correctly until you started dragging objects around in the scene view?

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Global trigger events
« Reply #8 on: October 24, 2015, 11:15:57 AM »
No, it was always happening with in-game movement. The scene window dragging was a red herring. I've got the scene working in slow motion. The main sprite is moving at about a tenth the speed I initially had it and it does - touch wood - seem to be counting the triggers correctly. When I run it with one of the other FSM running, the count starts going haywire again. That FSM sorts triggered objects into a couple of small arrays. I might delete that FSM and start again. Issue seems partially resolved, though not solved in the sense that I have any clue what's been happening.

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
Re: Global trigger events
« Reply #9 on: October 24, 2015, 11:49:14 PM »
My instinct is that if its working fine until an additional element is added (the other FSM doing the array stuff) then the problem is most likely in that new element.

Also, just cos it's always worth asking the basics - you do have a rigidbody component on your moving triggers and collision objects?

cats00eye

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Global trigger events
« Reply #10 on: October 25, 2015, 09:13:46 AM »
Yes, thanks. Rigidbodies all present and correct. I agree, I'm sure it's something to do with the other FSM. I thought it might be because it was doing something relatively intensive, sorting an array, and that might have somehow taken precedence over the triggers FSM, but that wouldn't account for the behaviour, which was adding way too many triggers rather than too few. Anyway, I'll build up the other FSM again crumb by crumb, and hopefully see where it goes pear-shaped. Thanks again for all your help.