- Home /
Selecting transform in FBX hierarchy csharp script
I am trying to set a transform called _target to an object in the hierarchy of a FBX object using csharp script.
I've got my script so that it selects the correct gameObject in the hierarchy of a FBX object. In this case it is Spine001_00.
Transform test;
test = transform.Find("Spine001_00");
Debug.Log(test);
Debug.Log(test) gives the result on the console window of :
Spine001_00 (UnityEngine.Transform) UnityEngine.Debug:Log(Object)
The following lines of code set test to _target and _target to transform.
_target is used throughout the script to determine the transform (co-ordinates) of the camera target.
test = _target;
_target = transform;
Running the game with the Play icon sets _target not to the root of my FBX and not to Spine001_00 (which is one level down the hierarchy). I can select Spine001_00 or any other object in the hierarchy (I'm selecting bones which are read by Unity as gameobject type), and the target adjusts itself fine during run-time, but I still need to manually select it when the code written is for it to be automatic.
Unity loses the focus of _target in the component editor on the inspector at run-time (ie _target is NONE) if the code is changed from
test = transform.Find("Spine001_00");
to
test = transform.Find("/Spine001_00");
which gives the result on the console window of
null UnityEngine.Debug:Log(Object)
Using transform.Find(string) is very... specific. Are you sure you need to hardcode this? Can't you assign it in the inspector when you set up the prefab?
mainly because I want to change my FBX objects often and testrun them through unity without using the inspector. Also because it would be useful to be able to change the target of the camera in-game.
I know this is old, but I totally stand by maggot. It's way more convenient to set up the hierarchy at run-time when you're re-importing models. And really, this should be an easy process so an artist can import a model, see it in game, make a few tweaks, and re-import it without breaking everything.
Answer by maggot · Nov 16, 2011 at 01:07 PM
Alright, I have got it working now. I've put the camera and tracker creation into myThirdPersonCamera script. It works both in the game window and in build and run.
Your answer
Follow this Question
Related Questions
Transform.gameObject References Itself?! 0 Answers
Syntax for a game object component variable on a transform in an FBX hierarchy? 1 Answer
keep gameObject in hierarchy folded when not selected 3 Answers
Animation Root Motion Problem 0 Answers
Moving objects in game using .transform does not stop 3 Answers