Cannot implicity convert type unityengine.transform

hello I’m getting a compile error that I cannot solve at minute 7:55 in this video using unity 5.6.3

Cannot implicity convert type unityengine.transform

using System.Collections;
using UnityEngine;

public class Player : MonoBehaviour {

	public Transform playerSpawnPoints;  //the parent of the spawn points
	public bool	reSpawn = false;

	private Transform[] spawnPoints;

	// Use this for initialization
	void Start () {
		spawnPoints = playerSpawnPoints.GetComponentInChildren<Transform> ();
		print (spawnPoints.Length);
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}
1 Like

Hi Veronica,

I think the problem is the use of GetComponentInChildren<Transform>, which returns a single Transform, instead of GetComponentsInChildren<Transform> (with an ‘s’), which returns an array of Transforms. The compiler is waiting for an array and only getting a single element, and it cannot implicitly convert it to an array.

Let me know if that solved it :slight_smile:

2 Likes

Yes that fixed it thank you so much! I couldn’t for the life of me figure that one out for some reason. Now the march of code goes on!

2 Likes

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

Privacy & Terms