SetPath at runtime does not move object



  • I'm new to Unity and obviously doing something wrong.
    Copied and pasted from the runtime example as I am doing everything programmatically.

    I am trying to move a 2d object and when I press Instantiate button just like the example, the path is created as well as the object at the beginning of the path however it does not move.

    player.GetComponent<splineMove>().SetPath(WaypointManager.Paths[path.name]);

    I've had a look at Walker2D and set splinemove etc but it won't move.

    Thanks in advance!



  • @Hyunsik I've also tried adding startmove but no luck.

    player.GetComponent<splineMove>().SetPath(WaypointManager.Paths[path.name]);
    player.GetComponent<splineMove>().StartMove();



  • From the scripting documentation, SetPath starts movement so you don't need to add a call to StartMove afterwards.

    SetPath (PathManager newPath)
    Changes the current path of this object and starts movement

    Do you see any errors in the console?



  • @Baroni Yeah I know but.. tried it anyway cus I didn't know what else to do.

    No no error.
    The path is drawn, the object is seen on the path but that's it. It just stays there and I can see from the example, as soon as you press the button it executes, the x axis' number decreases as the object moves as it should but that won't happen.

    Edit
    Just got errors from Dotween. These come and go. Don't always show up tho.

    DOTWEEN ► SAFE MODE ► DOTween's safe mode captured 2 errors. This is usually ok (it's what safe mode is there for) but if your game is encountering issues you should set Log Behaviour to Default in DOTween Utility Panel in order to get detailed warnings when an error is captured (consider that these errors are always on the user side).

    • 2 missing target or field errors
      UnityEngine.Debug:LogWarning(Object)
      DG.Tweening.Core.Debugger:LogSafeModeReport(Object) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/Debugger.cs:55)
      DG.Tweening.Core.DOTweenComponent:OnDestroy() (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:154)


  • Could you please post detailed instructions on how to reproduce your issue in one of the example scenes? E.g.

    Unity version: X

    1. Open example scene "Example7_Runtime"
    2. Add code to script "RuntimeDemo.cs" in method "XY"
    //code
    


  • These errors show up when I actually stop playing not during.
    Not sure this has anything to do with the object not moving..

    Here's the code. It's the same stuff I took from the runtime example.
    It is NOT your example project. I did mention earlier I copied and pasted stuff from your example project.

    And I don't know how to attach images here. I will send the images to your email address.

    Unity version : 2019.4.1f1

    1. Play
    2. Press Instantiate button
    3. Path & Object are created but nothing moves
    4. Stop playing
    5. Dotween errors show up
    void DrawExample1()
        {
            //GUI.Label(new Rect(10, 10, 20, 20), "1:");
    
            string playerName = "Player (Path1)";
            Vector3 pos = new Vector3(-25, 0, 10);
    
            //instantiation
            if (!example1.done && GUI.Button(new Rect(30, 10, 100, 20), "Instantiate"))
            {
                //instantiate walker prefab
                GameObject player = (GameObject)Instantiate(example1.playerPrefab, pos, Quaternion.identity);
                player.name = playerName;
    
                //instantiate path prefab
                GameObject path = (GameObject)Instantiate(example1.pathPrefab, pos, Quaternion.identity);
    
                //start movement on the new path
                player.GetComponent<splineMove>().SetPath(WaypointManager.Paths[path.name]);
    
                //example only
                example1.done = true;
            }
    
            //destruction
            if (example1.done && GUI.Button(new Rect(30, 10, 100, 20), "Destroy"))
            {
                Destroy(GameObject.Find(playerName));
                Destroy(GameObject.Find(example1.pathPrefab.name));
    
                //example only
                example1.done = false;
            }
        }
    


  • Hmmm weird. I just set the "Walker"s Ease Type Linear instead of Unset and now the tween is happening but it's weird. The object disappears and the path has this white line above the actual path.

    On the inspector
    Your prefab object > Spline Move (Script) > Ease Type

    Now the dotween errors no longer appears.



  • See this thread for posting screenshots.

    When you changed the Ease Type to "Unset", you did not specify any custom animation curve. It is below the ease type. No custom animation curve means the object does not progress on the path at all.

    Try to keep the Ease Type on "Linear" for now. What do you mean by "the object disappears"? Is it destroyed? Then maybe your destroy button is called as well?

    Also, on the splineMove script you set the PathMode to "Full 3D", but are using it in 2D. In the 2D example I've used a 2D PathMode.



  • Ahhh it was the 2d/3d part...! Now it moves and all. Thanks!

    So this white path is created above the path I actually drew and the object takes that path instead.. Why's that?

    alt text



  • The yellow path is your editor path; the white path is the actual tween path.

    I can only guess that you could have an offset on your child sprite, or set the movement to local, which would show that result.



  • Ah yeah I just figured out it's Spline Move > Size To Add
    I had it 1.1 just like the example and apparently that moved the object.

    Thanks for responding so quickly! Cheers


Log in to reply