Search Unity

Simple Waypoint System (SWS) - Move objects along paths

Discussion in 'Assets and Asset Store' started by Baroni, Dec 10, 2011.

  1. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Thanks @Justin-Wasilenko, will do! I chatted with Daniele yesterday. For now you can simply delete the DOTween folder in SWS and import the new version :)
     
    Justin-Wasilenko likes this.
  2. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Hi. I'm getting this error every time I press "P" to place a new waypoint.

    NullReferenceException: Object reference not set to an instance of an object
    SWS.WaypointEditor.OnSceneGUI () (at Assets/SWS/Scripts/Editor/WaypointEditor.cs:62)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.SceneView.CallOnSceneGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:2392)
    UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:1721)
    UnityEditor.SceneView.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:1553)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:272)
    UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:265)
    UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:232)
     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @username132323232, does this happen in a new or your existing project only? Do you have one SceneView window or multiple SceneView windows in your layout? Which Unity and SWS version and any other steps for me to reproduce this?
     
  4. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Thanks Baroni!

    1) Existing project, but a new scene.
    2) One SceneView.
    3) Unity 2017.1.0f3, SWS 5.4

    No other steps. I just followed your 60-seconds video. It worked a couple of days ago in the same project. I know it's weird :)
     
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Thanks @username132323232, mmmh could you try to close Unity, delete the Library folder of your project then start it up again, to see if that changes something?
     
  6. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Tried that and also created a completely new project with the same results. The script variable is null in OnSceneGUI().
     
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Not quite sure how the script reference is not initialized in OnInspectorGUI for you, as that should be called before OnSceneGUI. Is OnInspectorGUI not called at all? Going to investigate in a new project tomorrow as well.
     
  8. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    I put Debug.Log() in OnInspectorGUI() and in OnSceneGUI(). Here is the output:

    sws.PNG


    I know how difficult it is to debug this kind of problem remotely, so please let me know if there's any way I can help.
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @username132323232 imported SWS 5.4 in a new Unity 2017.1.0f3 project, added Waypoint Manager to the scene, tried both 2D and 3D paths, works as expected... could we please continue this over email and could you please send me your Unity project folder as a zip, where the error happens (e.g. the new project you've created) along with a screenshot of your full editor layout at the moment the error happens. Thanks!
     
  10. DChap

    DChap

    Joined:
    Dec 24, 2016
    Posts:
    23
    Hi, I've been digging through the forum posts and example code, but despite that I'm still having a lot of trouble trying to create events at runtime.

    Basically I have a bike looping endlessly on path01. It transitions to path02 (transition path) on a keystroke. Then I want it to transition to path03 once it reaches the end of path02 (and then loop endlessly on path03). Since events are called on the mover and not the path, I cannot create events for path02 (unless I do it at runtime).

    My attempt:
    Code (CSharp):
    1. void CreatePathEvent()
    2.     {
    3.         UnityEvent myEvent = pathEvents.moveRef.events[8];
    4.         myEvent.SetPath(WaypointManager.Paths[bikePaths.pathName3])
    5.     }
    ^This code is wrong obviously, but not being a coder, I'm kinda lost here =(
    What I want is to make an event where path02 waypoint 8 (the last waypoint) will transition the bike to path03.

    Any help would be appreciated.
    Thanks!
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @DChap,

    example 6 in the RuntimeDemo script would be what you are looking for, if you are going the route of movement script events. Something along the lines of:

    Code (csharp):
    1. myEvent.AddListener(delegate{pathEvents.moveRef.SetPath(WaypointManager.Paths[bikePaths.pathName3]);});
    There is no need to do that via events though. You could just add a collider to the last waypoint of the path, which has a script (or script with a UnityEvent) on it that calls SetPath on the movement script triggering it. An example for this (collider triggering event) is in the Example5_Events scene as well.
     
  12. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    I'm pretty sure it has something to do with my setup, otherwise everyone would be complaining. I was already about to email you the zip file, but then tried a workaround: edit an existing path taken from one of the example scenes. That worked, so problem solved as far as I'm concerned :) Thanks for trying to help. SWS rocks!
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @username132323232 I'm not really happy with the workaround you are doing - I would still like to investigate your project setup, in case someone runs into this as well in the future, if you find the time to send me your project zip.
     
  14. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    No problem. Do you prefer your website email or a private message to your Unity inbox?
     
  15. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Website email :)
     
  16. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Emailed yesterday. Did you receive it?

    Also, is it possible to stop the object for a few seconds at each waypoint?
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    No, I didn't receive any email from you @username132323232. Have you sent the email to info [at] rebound-games [dot] com?

    For stopping at a waypoint for some time (which means pausing), you could use the Pause method on the movement script, that takes a float parameter (time in seconds), added as an event to the waypoint.
     
  18. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Yes. I emailed you another message without the project zip file a minute ago. Please let me know if you received that.

    That's perfect! Your Events system is pretty cool. I think you should rename SWS to "Simple to use, but very powerful Waypoint System" :)
     
  19. hottabych

    hottabych

    Joined:
    Apr 18, 2015
    Posts:
    107
    I need an object to move to a certain waypoint, and stop.
    But I can not find such a method in SplineMove, there is only GotoWaypoint() which instantly teleports the object to the given waypoint (wrapper over DoTween.GotoWaypoint).
     
  20. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @hottabych There are several ways to do that:
    - you could set the 'startPoint' to the desired waypoint, and add an event on the movement script at runtime, which calls Stop() at this waypoint. Just set 'moveToPath' to true and call StartMove() on the movement script as usual.
    - you could set the 'startPoint' like above, but add a collider to the waypoint which triggers Stop() on the movement script, when colliding (instead of using events).

    Both options and code snippets are showcased in the Events sample scene.
     
  21. MartinGebske

    MartinGebske

    Joined:
    Jun 18, 2013
    Posts:
    13
    Hey folks, first - congratulations to the great asset. Saved me a lot of time and nerves. I just wonder. Can start the movement based on an event? like clicking on the item-to-move and THEN it starts moving? After finishing I can click again? Hope I'm missing something or being too stupid for the search ^^
     
  22. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @MartinGebske, sure, disable "OnStart" on the movement script in the inspector and call StartMove() on it whenever you like. There are actually several samples for runtime controls in the runtime example scene.
     
  23. MartinGebske

    MartinGebske

    Joined:
    Jun 18, 2013
    Posts:
    13
    Darn... This was too obvious for me x)) Thanks a lot!!
     
  24. jingray

    jingray

    Joined:
    Feb 6, 2015
    Posts:
    53
    How to change speed, ease runtimes ?! Thanks
     
  25. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
  26. teiadev

    teiadev

    Joined:
    Sep 14, 2017
    Posts:
    3
    Do you know how to find the nearest segment if you have an arbitrary Vecotr3?
     
  27. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @teiadev there is no function built in for that, but a feasible way would be to loop over the waypoints array of the path manager and do a Vector3.Distance check for them. Bezier paths also have a path points list, which holds all of the single "dots" on segments, so you would be able to find a more or less exact position on that between segments too.
     
  28. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    181
    I am just drawing a simple curved line, but I want to move it with the parent object. Is there somewhere I can do a transform.transformpoint or similar to fix this?
     
  29. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @Redrag not sure how you are drawing the curve, so if it's with a LineRenderer, you would need to update the points you are feeding into it. Parenting the path to your moving object should be sufficient to recalculate the path points. There is a sample included (in the advanced scene) which shows a ball following a rotating path, so that might help as well.
     
  30. armnotstrong

    armnotstrong

    Joined:
    Mar 3, 2017
    Posts:
    21
    Hi,

    can I get the whole length of the path and a specific point on the path by the distance from the start with your plugin? let's say we have a curved path, and its length is 100 and we want to get the pointing vector of which has a distance of 30 from the start on the path, really need that. Can we do that? thanks.

     
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @armnotstrong, if an object is moving on a path (so the path is initialized), you can get the Vector3 at a specific distance via the underlying DOTween tween properties. There's the tween.PathGetPoint method, which returns the Vector3 at a specific percentage of the path. So if your path has the length of 100, and you would like to get the Vector3 at the distance of 30, that would be PathGetPoint(0.3f).
     
  32. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    181
    I missed the fact that you need to restart after clicking on ' On Update'.

    However, now I have found in runtime, the positions only update when I click the gameobject which has the scripts (In inspector). It then updates once then stops until I click away then back again. Any ideas?
     
    Last edited: Sep 15, 2017
  33. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @Redrag If you are using bezier paths, the BezierPathManager has a method (CalculatePath, see the scripting reference) for updating the path points at runtime. It doesn't update automatically because of performance reasons. Default PathManagers don't have this, since their paths are calculated by the objects moving on them directly at tween initialization.
     
  34. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    181
    OK - I have changed to PathManager and all working correctly now. Many thanks.
     
  35. KITPUNK

    KITPUNK

    Joined:
    Nov 11, 2014
    Posts:
    13
    Not sure what I'm missing, but I'm trying to move an object along a square path in which I've disabled "draw smooth lines" in the path editor, yet in runtime, it reverts back to bezier curves. I assume that feature is strictly for editor view only.

    What do I need to do in order to have it stay as straight lines in runtime without creating a bunch more nodes (I'm also using playmaker).
     
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @Giga_Steve correct, "draw smooth lines" does not affect the path, that's for editor visualization only. For a straight path, you would not use bezier paths (as they have more points by definition), but the default standard path. In the movement script on your object, you can then choose path type = linear.
     
  37. KITPUNK

    KITPUNK

    Joined:
    Nov 11, 2014
    Posts:
    13
    Wonderful, thanks! I even saw that option early and totally blanked on it, haha. Works like a charm.
     
  38. BitGamey

    BitGamey

    Joined:
    Jun 11, 2016
    Posts:
    52
    I'm trying to set up waypoints around a 3D town. I want to have pauses when vehicles reach junctions and will be sending them in random directions when they have multiple turning options. I have looked at the examples but I don't see where waypoint pauses are specified or how to make random waypoints. What am I missing? Thanks in advance :)
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @Laniemme delays can either be added
    • directly in the movement script, by expanding the events section and adding its Pause(seconds) method at the desired waypoint(s) - see the events example scene for a sample
    • at runtime via code, by adding the movement script's Pause(seconds) method to the events list at a specific waypoint - see the events example scene as well
    • triggered by a collider, when your object touches it, you would call Pause(seconds) on the colliding movement script - events example scene too
    For junctions, you will need to know the path name and waypoint index your object will move to next. Using this information, you can set the startPoint value on the movement script to the new waypoint index, and call SetPath on it by passing in the new path component.
     
    BitGamey likes this.
  40. RobertEspinoza

    RobertEspinoza

    Joined:
    Aug 18, 2014
    Posts:
    10
    Hello Baroni. I'm having an issue with SetPath. I'm calling moveToPath = true, and startPoint = 0 before calling set path. my splinemover has a bad transform "bounce" once it reaches the 2nd waypoint. It bounces and returns to waypoint 0 once it reaches waypoint 1. Any idea what I could be doing wrong? Appreciate any help
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @four-d-oz, I'm usually bad at guessing - to save some time, could you please send a small repro project to our support email (found on our website, or last page in documentation pdf), so I can take a look at your setup directly.
     
  42. fla-rar

    fla-rar

    Joined:
    May 1, 2014
    Posts:
    246
    Hi.
    wanted to know, how are those obstacles there.
    if the program does not show them in the hierarchy lable.
    I can make my soldiers avoid obstacles.

    in other words:
    it is obvious that there is an obstacle there. (seen in the video)
    but I can not find it anywhere,
    my question is how can I do to create those obstacles please.
    I tried and I did not succeed.
    please help.

     
    Last edited: Oct 12, 2017
  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    While I can't look into your project and make a guess by watching a video, it seems that you are using the navMove movement script on these soldiers? Have a look at the NavMesh then, which may needs a rebake.
     
  44. fla-rar

    fla-rar

    Joined:
    May 1, 2014
    Posts:
    246
    please ....
    how instantiate a prebab walker that include already the path please ?
    .

    prefab not include.jpg
     
  45. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @fla-rar paths are bound to the scene. You cannot assign scene objects to prefabs. If you instantiate a prefab with a movement script, you can call SetPath on it to assign the path, but disable "OnStart" in the inspector first.
     
  46. fla-rar

    fla-rar

    Joined:
    May 1, 2014
    Posts:
    246
    Thanks .... ! i will try !
     
  47. fla-rar

    fla-rar

    Joined:
    May 1, 2014
    Posts:
    246
    sorry ...
    just to know ... if you have some basic manual to use it ?
    i search on internet but the link send another place.
    but basic, i need to know the different
    standar and bezier please
    .
     

    Attached Files:

  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @fla-rar please see the documentation pdf included in the SWS folder for a basic manual and differences on standard and bezier paths. You can also just create both of them and see the difference yourself - standard paths are basic curves, while bezier paths have several more points and allow for detailed definition of their segments. Also, Wikipedia provides great information for both type of curves.
     
  49. fla-rar

    fla-rar

    Joined:
    May 1, 2014
    Posts:
    246
    thanks so much ... ...
    i didnt know the pdf manual .. thansk so much, i apreciate !
     
  50. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hello @Baroni ,

    just a quick one. My "move to path" speed of an object is ridiculously low compared to the speed (time value: speed) of movement between the paths. Is there any way of adjusting it? Or is it the same as speed of movement between paths and i'm doing something wrong? It's a 2D game, everything's set on Z: 1, including paths.