Varun Panchal
Varun Panchal

Reputation: 11

Unity - Prefab with Sub-Elements Expansion Button Missing in Project Panel

I have been following along with a course. In this course a GameObject called "Path (0)" is added, this GameObject then has three sub-GameObjects ("Waypoint (0/1/2)"). In the tutorial, the guy drags the parent GameObject "Path (0)" into a folder called Paths in the Project panel to create a prefab. This prefab is shown with a handle to expand it. He then expands this prefab to see the sub-elements which can be dragged into the Inspector, as shown below (expand button highlighted with red box) enter image description here

When I perform these operations, the Project panel does not have an expand button on the "Path" prefab (see below)

enter image description here

Why does my prefab object in the Project panel not have these expansion buttons?

Basically, what he does is he creates a script component with enemy prefab.(attached bellow). and the childobject "waypoints" are marks in scene where enemy will move. I uploaded a part of tutorial on youtube, which i will delete once the problem is solved. if youtube dosent delete it. Please help i am half through the tutorial.

https://youtu.be/NGpaHSmktic

public class EnemyPathing : MonoBehaviour { [SerializeField] List waypoints; [SerializeField] float moveSpeed = 2f; int waypointIndex = 0;

void Start()
{
    transform.position = waypoints[waypointIndex].transform.position;
}

// Update is called once per frame
void Update()
{
    Move();
}

private void Move()
{
    if (waypointIndex < -waypoints.Count - 1)
    {
        var targetPosition = waypoints[waypointIndex].transform.position; // this is where we go to
        var movementThisFrame = moveSpeed * Time.deltaTime; // this is how fast we want to go to
        transform.position = Vector2.MoveTowards(transform.position, targetPosition, movementThisFrame);

        if (transform.position == targetPosition)
        {
            waypointIndex++;
        }
    }
    else
    {
        Destroy(gameObject);
    }
}

Upvotes: 0

Views: 557

Answers (1)

Entapsia
Entapsia

Reputation: 51

It must be because you don't have the same unity version.

Simply double click on Path0 and it will open it. In the Hierarchy tab, you will see the asset and its elements. If you drag back Path0 to the scene, its children will appear too.

It's because you're not supposed to drag a child asset away from its parent. I don't know how it is used in your tutorial, but if needed, you can make a child prefab too by dragging it to the folder (After double clicking on Path0).

Edit :

I don't really know what you can do to have the exact same situation, but here is another way :

-create a tag 'waypoint' and set this tag for Waypoint0, Waypoint1 and Waypoint2 (in your asset, or before creating it).

-In the Start method of your EnemyPathing.cs add this :

this.waypoints = new List<Transform>();
foreach(GameObject g in GameObject.FindGameObjectsWithTag("waypoint"))
{
    waypoints.Add(g.transform);
}

So, it will automatically add your waypoints, even if you have more or less than 3 in your scene.

Upvotes: 0

Related Questions