Waves and Path Prefabs in Laser Defender

In the new prefab system i’m a little bit confused. I can’t assign Paths from Hierarchy to Waves even though they are instances of prefabs but only from prefab folder, so i assign it like Unity want but… In folder Prefabs’ transforms are set to 0,0,0 so my enemy spawn with these coordinates. My half-solution is to set in hierarchy Path instance like i want it to, copy variables from transform and past to prefab transform like on the screenshots . But then i directly set prefab variables and probably i won’t be able to add 2 waves of the same path but with different transform (eg. first wave from left side to right near the top of the screen and second form right to left at the middle of the screen) Can someone help me how to make a real solution for this problem?Dwa

Hi,

The best would be to drag your path prefab into your scene and to adjust the waypoints. If you need to assign the single waypoints to an array in the Inspector, you can do that by dragging and dropping the game objects from your Hierarchy into the fields.

Alternatively, you could click on the circle next to the field and select the waypoints from the list. This also works with prefabs, but don’t forget to assign the changes of the path game object in your Hierarchy to the prefab. Dragging and dropping the children of a prefab in the prefab mode does not work for some reason.

1 Like

Hi Nina, thank You for respondig. In lesson 96 and 97 in 2D unity course Rick drags and drops Path instance from Hierarchy to Wave 2 inspector, then in script He uses foreach loop to add transforms from children (waypoints) to List. Now i can’t assign (becouse of Unity 2018.3) Path from hierarchy but only from prefab folder, its not about the waypoints. When you open path prefab in prefab mode it’s transform is set to 0,0,0 waypoints are near the Path pivot (waypoints: first is 3,1,0, second 0,1,0 and third -3,1,0)so when script transform Enemy position it is transformed to that exactly waypoints transform and that teleports enemy there. And my half-solution ive mentioned is to change path prefab tranform in prefab mode (couse i cant assign instaces from hierarchy). Maybe if you watch these lessons from the course you will understand my problem ( if you have time for it ) :slight_smile:

Thanks for the explanation. Unfortunately, the whole prefab system in Unity 2018.3 has changed, so I usually try to understand the goal and provide a solution instead of trying to apply the steps that were made in 2018.2 to the new version.

By definition, a real solution is a solution that works.

You cannot assign the position of a prefab parent to a copy of the prefab in the scene, which makes sense as you don’t want to have all copies of a prefab end up at the same position when changing the prefab. If you need the parent to appear at a specific position, I’d rather set the position to (0, 0, 0) and change the relative position of the children.

In the prefab mode, you can move the children relative to their parent. The prefab mode is no scene, so it does not make sense if you could move the parent in it. I assume the default position of (0, 0, 0) is just there to show that the Transform is still part of the prefab.

If you want to use the same prefab two times in the scene but change its position, you need to do that manually, and you need to keep both objects in the scene. The objects in the scene must be assigned to your wave, not the prefab.

Alternatively, you could drag one of the objects into your prefab folder making it another prefab. Then you can use both prefabs.

1 Like

Thank You so much Nina. Now I better understand prefab system and will solve this problem somehow.

You’re welcome. :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms