Context: Placing customizable guns on a customizable base vehicle.
I have a game object with a script attached. The script contains variables for the base model and the guns model.
var baseFile : Transform;
var gunFile : Transform;
function Start(){
// create base mesh
newBaseModel = Instantiate(baseFile, transform.position, transform.rotation);
// make a gun and position it
gunLocator = newBaseModel.Find("gunLocation");
print(gunLocator); // This line prints out fine
print(gunLocator.position); // This line errors out
newGun = Instantiate(gunFile, gunLocator.position, gunLocator.rotation);
newGun.localScale = gunLocator.localScale;
newGun.parent = transform;
}
This is all that's in my scene. When I hit play, I get the error:
NullReferenceException
VehicleBuilder.Start() (at Assets\Scripts\VehicleBuilder.js:11)
Once playing, I can look at my instantiated vehicle in the hierarchy, expand it out and find the "gunLocation" locator, and the line that prints properly prints out UnityEngine.Transform.
Any ideas why I can't access the position of the locator in an instantiated object?