Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by maggot · Nov 10, 2011 at 07:36 PM · c#transformfbxhierarchy

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)

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Nov 10, 2011 at 10:14 PM 0
Share

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?

avatar image maggot · Nov 10, 2011 at 10:24 PM 0
Share

Well I could, but I want to hardcode everything

avatar image syclamoth · Nov 10, 2011 at 10:30 PM 0
Share

WHY????

avatar image maggot · Nov 10, 2011 at 10:52 PM 0
Share

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.

avatar image EccentricDuck · Aug 02, 2013 at 12:48 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges