I am try to find the children of the transform that I insantiate. This is my code:
public Transform GetLevel(int _currentLevel)
{
string levelName = "Level" + _currentLevel;
Transform level2Load = MonoBehaviour.Instantiate(Resources.Load("Prefabs/Levels/" + levelName)) as Transform;
Debug.Log(level2Load.childCount);
return level2Load;
}
The problem is that I am getting the following error:
NullReferenceException: Object reference not set to an instance of an object LevelLoading.GetLevel (Int32 _currentLevel) (at Assets/Resources/Scripts/LevelScripts/LevelLoading.cs:10)
Does anybody know why?
edit*
The wierd thing is that it does find the transform and instantiates it. But it can't find the chrildren.
The children do appear in the scene, and if I attatch an script to the transform that looks for the children it finds them.