transform.Find returning local instead of world position

Hey,

I created a class with the following code:

 #pragma strict
class Level {

	var levelPrefab : GameObject;
	var output : Vector3;
	var spawnPoint : Vector3;
	
	var isEnemy : boolean;
	var isUsed : boolean;
	var isGenerating : boolean;
	
	/*
	Assigns the output of the level prefab
	*/
	function GetOutputPosition() : Vector3 {

		output = levelPrefab.transform.Find("Output").position;
		return output;
	}
	
	/*
	Assigns the spawnPoint of the level prefab
	*/	
	function GetSpawnPointPosition() : Vector3 {
	
		spawnPoint = levelPrefab.transform.Find("spawnPoint").position;	
		return spawnPoint;
	}
	
	/*
	Enables/Disables the trigger that generates a new level	
	*/
	function ToggleTriggerGenerateLevel() {
	
		levelPrefab.collider.enabled = !levelPrefab.collider.enabled;
	}
}

The levelPrefab Object has a child named Output which I need to get the world position. After instantiating the prefab I’m calling the GetOutputPosition() but the Vector3 that is returning is from the local and not the world position of the object.

How can I solve this?

Thanks

I have an Array of Level Objects

var levelsArray : Level[];

and I’m running this lines from another script:

GameObject.Instantiate(levelsArray[rndNumber].levelPrefab, levelPosition, Quaternion.identity);
	
	levelPosition = levelsArray[rndNumber].GetOutputPosition();

Ehmm your Level class isn’t a component or scriptable object so when do you create an instance of this class and where do you use it / initialize? It looks like you use the prefab reference to get the position. All in all the code you’ve posted doesn’t make sense without the other parts.

transform.Find doesn’t return a position, it returns another Transform. The .position property always returns the world position.

If it helps, each transform also has a localPosition property

THis question has already been answer here: