Feature Request: Spawn Multiple Instances along Path



  • I have modified the script in my previous reply to also take spawned objects with a movement script on them into account.  ;)

    If the object prefab you assign in the PathSpawner has a splineMove script attached to it, the PathSpawner will not only spawn the object but also let it move on its path, starting from the position it has spawned it at.



  • Thanks for the modification. I know others will find this useful but I am coming up with odd behaviors with this script.

    The new version of the script seems to spawn all the instances on Waypoint 0, no matter what the minimum and maximum distance is set too. They do move though.

    Even the non spawned Original game object with the Path Spawner script goes to Waypoint 0 even if it has a different start point assigned.

    If I take out the below code the objects spawn at the correct positions.(but do not move of coarse)

    			objMove.pathContainer = move.pathContainer;
    
    			objMove.StartMove();
    			objMove.tween.ForceInit();
    			objMove.tween.fullPosition = objMove.tween.Duration() * perc;
    

    Do you get these behaviors on your part? The test scene I set up is very simple.

    Also,
    When the bool "On Waypoints Only" is checked the do spawn on the waypoints but do not move.

    Sorry for the hassle.

    Raymond



  • I've tested with a default path and it works as expected there. Could it be that you are using a bezier path?

    Even the non spawned Original game object with the Path Spawner script goes to Waypoint 0 even if it has a different start point assigned.

    Not sure what you mean here - the game object with the PathSpawner script only needs a movement script for reading out the path. You should not enable "OnStart" on it, or otherwise try to start movement, or assign a startPoint to it, as it is ignored anyway. The spawned objects can have a movement script, but they should not make use of "OnStart" or "startPoint" either, because the PathSpawner places them at the correct (random) position on the path.



  • For my test scene I am using a regular path(non bezier). But I was planning on using this on both non bezier and bezier paths in my game if possible.

    In regards to the below statement:
    Even the non spawned Original game object with the Path Spawner script goes to Waypoint 0 even if it has a different start point assigned.

    I meant that even the game object that has the move script and Path Spawner script goes to Waypoint 0, even if  has a start point of  Waypoint 3 for example.

    If I Disable the Path Spawner script it goes to the correct Start Point.

    My SWS asset is updated so I not sure why my path behavior is different than yours. I am using Unity version 2017.2.1f1 Personal (The latest Version).

    I could export my scene an send it to you, but not sure what email to send it to? administrator@rebound-games.com or info@rebound-games.com

    Thanks again,
    Raymond



  • *I meant that even the game object that has the move script and Path Spawner script goes to Waypoint 0, even if  has a start point of  Waypoint 3 for example.

    If I Disable the Path Spawner script it goes to the correct Start Point.*

    This doesn't matter - as I said above, the PathSpawner script only initializes the path positions at runtime. It is not designed to go anywhere, so leave all settings on its movement script at the defaults. You should only have one PathSpawner script per path. In fact, you could even attach it to the PathManager game object.

    The objects you spawn can have a movement script, but this should be left at the defaults too (except speed, ease type or other position unrelated things).

    Both email addresses work, but info@ is the main support email.



    • updated PathSpawner script above to correctly move prefabs spawned with "On Waypoints Only" on the path too.

    Note that when spawning an object with a movement script on the last waypoint, it immediately jumps to the first waypoint (if "close loop" is disabled), so it looks like two objects are spawning at the first waypoint. You can limit this by setting the "Max Spawn Count" on the PathSpawner to the waypoint count - 1. I do not prevent this behavior, since it could be desired when using a closed loop (where the object at the last waypoint would move to the first).



  • Awesome Work. This makes my project so much more developer friendly. It has allowed me to delete several game objects in the Unity Editor because now I can just spawn them along the path.

    Thanks for the great effort.

    Raymond



    • updated so that "On Waypoints Only" takes "Max Spawn Count" into account too (removed the prior notice about it not supporting that)


  • Hello Baroni,
    is it possible to orient the instances along path?
    Thank you,

    Manuel



  • Hello Manuel,

    of course - in the script, after it says "SpawnAtPos(tweenPath.PathGetPoint(perc));", you would just get a position further along the path e.g. using tweenPath.PathGetPoint(perc + 0.01f) and orient the object to that position.


Log in to reply