Possible event bug?



  • Hello again

    I've been using event for a while now and things would get messed up at some point and just figured out that when object reaches waypoint 0, callback isn't called but I'd get callback twice at waypoint 1. After that everything happens as it should. Could you please check? It could be my shitty code but I've tested so many times now.

    Thanks



  • Based on your description I cannot test anything reliably to reproduce what you are experiencing. Please provide detailed repro steps.



  • I'm moving a couple objects on the same path.
    Setting events to each one of them.
    When each object reaches waypoint 0, I don't get callback but when they're at waypoint 1, I get callback for waypoint 0 and then another one for waypoint 1 twice continuously. After that all callbacks are called as they should. It's just the very first waypoint that is "sent back" to waypoint 1.

    I also check whether all events are being set correctly and everything seems fine.

    public void EventSetter(List<WorldTile> wts)
        {
              for (int i = 0; i < wts.Count; i++)
            {
                int iz = i;
                WorldTile wt = wts[i];
                for (int j = 0; j < sms.Count; j++)
                {
                    int jz = j;
                    bool isLast = i == wts.Count - 1 ? true : false;
                    UnityEvent tempUE = sms[j].events[i];
                    carEvents[jz].Add(tempUE);
                    tempUE.AddListener(delegate { ActionForWaypoints(wt, isLast, jz, iz); });
                }  
            }
        }
    
    public void ActionForWaypoints(WorldTile wt, bool isLast, int carIdx, int waypointIdx)
        {
    // EVENT CALLBACK
        }
    


  • I just did some more tests.
    Turns out it's not about first waypoint's event.

    When an object hits a waypoint, I get all callbacks from all the points it didn't hit before reaching to that point.

    For example, x is my object and os are waypoints.
    I skip the first 2 waypoints and hit the third. Then I get event callbacks for waypoint 0, 1 and then 2.

    o --- o --- x --- o --- o



  • Honestly I still don't understand what you are doing in that code, since there are variables not defined in that snippet like 'sms'. It does not look related to 'wts' at all, although you are using it in an inner loop of 'wts.Count'. Other variables seem to not have any affect like 'jz' which is always equal to 'j', so you could just use that.

    When an object hits a waypoint, I get all callbacks from all the points it didn't hit before reaching to that point.

    In your example, are you using moveToPath to the third waypoint then? Or how are you 'skipping' 2 waypoints and 'hitting' the third? I can only tell that this does not happen in the example scenes, events sample.



  • Ok. sms is a List of splineMoves. As I said I'm moving a couple objects and I save their splineMove scripts in a list and right there I'm just setting events to each one of them.

    wts is a List of class variables that contain waypoint positions from path created using SWS.

    So I am going through waypoints and then from each waypoint, again going through splineMove of all object and set event to each object at each waypoint.

    And no I can't just use i and j because I'm sending parameters and if you send parameters as they are (i and j), you would get the last values of the loop. It took me some time to figure this out too actually I had no idea. Try it. You're sending instance of i and j so you always get the last values in callbacks.

    Yes I am using moveToPath to front waypoints.

    o --- x --- x --- x --- o --- o

    os are waypoints and xs are objects.
    That's how I start moving objects. From where they are at now.

    They've moved to their next waypoints as seen below

    o --- o --- x --- x --- x ---o

    So now you get event callbacks.
    Object 0 will get callbacks for waypoint 0, 1 and 2 continuously. Object 1 gets 0, 1, 2 and 3 and so on.

    Objects get event callbacks from the very first waypoint on path that did not trigger event to their currently hit waypoint.



  • Thanks. So to keep this short, you are telling me that a moving object

    • with events added to each waypoint at runtime
    • moveToPath enabled
    • placed at one waypoint in the middle of the path
    • startPoint set to the next waypoint

    will fire all previous events including the next. But only once and later event callbacks are fine.

    If so, I will try to reproduce this soon.



  • Yes! That's it.
    Sometimes objects are placed somewhere between two waypoints but yeah. Each object always moves towards next available waypoint on path.

    Thank you.



  • I was able to find the cause of this. The issue is with adding events while moveToPath is true and the object is not on the path, but moving to it.

    The reason this causes issues is because the 'moveToPath' behavior is actually a separate tween. While moving to the path using moveToPath, the actual tween on the path is not initialized. So when adding events right at game launch, you are basically adding events to the 'moveToPath' tween. Upon reaching the path, DOTween notices that the previous events were not fired and tries to catch up by firing all of them at once.

    A quick workaround for this is to add events when moveToPath is false, i.e. the object is moving on the target path. More callbacks will be added soon to make this easier.



  • Oh.. I was expecting an actual fix/update because it is a bug but okay no problem!

    You mean after creating path with moveToPath set to true and have started moving objects by .StartMove, set moveToPath to false right before setting events?
    I just tried that but that didn't help.

    public void MoveTrain(List<WorldTile> wts)
        {
            savedTileData = wts;
    
            for (int i = 0; i < cars.Count; i++)
            {
                GameObject car = cars[i];
    
                sms[i] = car.GetComponent<splineMove>();
                sms[i].moveToPath = true;
                sms[i].pathContainer = pm;
                sms[i].speed = 0.5f;
                sms[i].startPoint = StartPointManager(i);
                sms[i].StartMove();
                sms[i].moveToPath = false;
            }
            EventSetter(wts);
        }
    

    Thanks



  • No, moveToPath is true as long as your object is moving to the path. You can set events when the object reached the path (when moveToPath is false). You do not modify moveToPath for that purpose.

    Regarding a fix: we do not store events somewhere, they are applied to the current tween immediately. So if you are moving to the path, events are used for that tween - which is the wrong one, in your case. Maybe some other developer would like to use events on that moveToPath tween instead. Since the behavior was only reported once, the above workaround still allows both options.



  • Sorry I just saw this reply.

    I really don't know what you're saying at all... help me understand please.
    So I've started moving objects with their events set accordingly. And then what?

    You can set events when the object reached the path (when moveToPath is false)

    Um the set of objects is on path already even before they start moving. Let me show you a screenshot -
    alt text

    Just to clarify, events need to be set before they reach their next points so that the logic in the callback would perform. Because all callbacks for previous points are called all at once when they hit their first points, all calculations in the callback method gets messed up.



  • Please see this image.
    https://www.autodraw.com/share/TQHTF4EAW06Z

    • You are setting events while the object is moving to the path. This does not work.
    • You can only set events when the object is on the path (see red text in image).

    Your options are
    -> disable moveToPath, then the object will initialize the path tween immediately, and you can set events.
    -> or, wait until the object has reached the path, then set events.
    -> or, do not use events at all. But add colliders on each waypoints which will trigger your custom methods (see events example scene, there is a sample for colliders too).

    Hope this clears it up. I will look into how to add events for the "Path Tween" when moving on the "moveToPath Tween" at a later point.



  • Ah ok so I just CANNOT. In your previous reply you mentioned "workaround" but that was misleading. None of the options works for me as I must use moveToPath before objects reach the path and this happens over 500 hundreds of times during game. This is crucial for my game as I constantly create new path over and over for multiple objects.

    I also want to avoid creating and destroying a bunch of colliders over and over as that affects the performance..

    All events from previous points being called all at once with the use of moveToPath is clearly a bug. That should not happen as those points aren't even being touched.

    Also, you say I can set events when objects are on the path but that is not true. I have tested this hundreds of times.
    I have a set of objects and some of them are away from the path, some others are actually on the path before they start moving. The ones that already were on the path before moving/setting events also trigger all events from previous points when they hit their first point.

    I understand this isn't your priority because so far no one else seems to need this fixed but let me know when you feel like fixing it. Thanks.



  • Also, is this happening because there's something wrong with DOTween or is it just SWS?



  • Watch your language. I do not "feel like" replying to this thread anymore with your passive aggressive tone. There is a workaround and I have stated it numerous times above and also in the image. I did say that disabling moveToPath is one out of 3 options - you do have to use that if you rely on moveToPath.

    Locked.



  • I was on vacation last week. Back in the office today and took a second look at it, it is an internal DOTween thing.

    DG.Tweening.Tween:OnTweenCallback(TweenCallback`1, Tween, Int32) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:309)

    Happens regardless of moveToPath being enabled or not, as DOTween iterates over all OnWaypointChange events to the current startPoint (firing all previous events). Since DOTween comes as DLLs I am not able to "fix" it directly, but I added a workaround in SWS' OnWaypointChange method checking for the current index fired by DOTween. Will be live in the update within 24 hours.


Log in to reply