Is there a solution for the waypoint prefab issue?
I have a prefab of an enemy AI car, and a script which will instantiate this prefab at set intervals. I want to have the instantiated prefab follow a waypoint course, to strafe our base. The problem is that when I make a prefab out of the enemy car, it loses the waypoint circuit assigned to it. I tried re-assigning the waypoint circuit to the prefab, but Unity won't let me do that. I tried making a prefab out of the waypoint circuit. Unity will allow me to assign that prefab (of the waypoint circuit) to the prefab of the enemy car, but when instantiate that prefab I get the error message:
"IndexOutOfRangeException: Array index is out of range. UnityStandardAssets.Utility.WaypointCircuit.GetRoutePosition (Single dist) (at Assets/Standard Assets/Utility/WaypointCircuit.cs:66)"
I'm hoping that there is a way to use code to assign the original waypoint circuit to the circuit variable of the WaypointProgressTracker.cs (the script attached to the car, where you drag & drop the desired waypoint circuit.)
The real problem is that I am not (yet) much of a coder - still working my way through the beginner set of tutorials... I'm just unsure what my approach to this problem should be - I tried making an alternate version of the WaypointProgressTracker.cs script, to allow me to assign the waypoint circuit on Start, but that effort failed every which way, again, because at this point, I'm still in waaay over my head. :)
If anybody can share a working solution for this issue, I would be most grateful. At this point, the work-around is pretty ugly - have a bazillion copies of the enemy car in scene, but set inactive, and a script to activate them... works, but I'd really prefer to have the cleaner approach of instantiating a prefab.
Thanks for any help!
you usually need to do three things:
- instantiate your car.
- Get the WaypointProgressTracker script from the instance.
- assign the waypoints to it
this should be done in a $$anonymous$$onoBehaviour that's part of the scene and knows the waypoints
Answer by GKuhns · Mar 29, 2017 at 04:24 AM
Well, I have step one and (sort of) two - I can instantiate my car, and I can make a variable for a public Behaviour, and assign the WaypointProgressTracker script to it in the inspector... What I can't find a way to do is the last step - assigning the desired waypoint circuit. As I mentioned, I tried making an alternate version of the WaypointProgressTracker.cs script, to allow me to assign the waypoint circuit, but because I really don't know my way around coding yet, I can't figure out exactly how to do that last step....
Any ideas?
Answer by Zykroma · May 29, 2017 at 07:00 PM
Hello ! I was having the same problem and I figured out what was going on. There is 2 Waypoint Circuit scripts. You need to use the one that do not propose to change the color and you need to drag the script into the inspector. Not the gameObject.