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 vished · Feb 22, 2011 at 11:50 AM · gameobjecttransformfbxhierarchysyntax

Syntax for a game object component variable on a transform in an FBX hierarchy?

I have a known incoming transform hierarchy from Maya like this:

root|one|two|three

If I want to refer to a variable on transform three in Maya I would use:

root|one|two|three|threeShape1.var

After importing into Unity as an FBX how do I refer to a public game object component variable on transform three without sorting through everything in the scene using "find"?

Thanks!

Feb26: Wow - is this too hard? What I was expecting is something like:

transform(root/one/two/three/).gameObject.componentName.variableName

Maybe the question should be:

How do you refer to a unique game object component on a unique child transform? (From a script component on the root transform)

Do you really have to maintain a hash table of all your objects? Shouldn't Unity do that? http://answers.unity3d.com/questions/11959/transform-find-and-instantiate-do-not-return-the-same-type

I'm completely confounded by the relationship between a transform and a game object. All 3D software uses transform hierarchies as the basic organisational structure - is Unity some how different??? http://unity3d.com/support/documentation/ScriptReference/Transform.html http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html

Comment
Add comment · Show 3
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 by0log1c · Mar 07, 2011 at 01:04 AM 0
Share

A GameObject is the Parent, requiring a Transform Component. When beco$$anonymous$$g a child of another GameObject, it becomes a Transform-GameObject you can't access through Components, for some obscure reason.

avatar image by0log1c · Mar 07, 2011 at 01:07 AM 0
Share

Any time you'll be accessing a Transform/Component/GameObject more than once, I recommend storing it in a variable/hashtable/array.

avatar image vished · Apr 23, 2011 at 03:21 AM 0
Share

Thanks -but if you know what it is called and that the name is unique why do you need to parse through every object in the scene to search for it? Seems like a waste of resources and unnecessarily complex?

1 Reply

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

Answer by by0log1c · Feb 26, 2011 at 05:49 AM

I couldn't tell for C#, but JScript goes something like this. I used this to retrieve the hand of my character so I could AddMixingTransform to an animation. Store the reference in a variable if you are to call this often.

var theHand = gameObject.transform.Find("Model1/Body2/Hand3");

That'll consider parent GameObject as the current root. Tweak around to get what you need.

EDIT: Or a long example for accessing a variable into a script from a child GameObject/Transform.

var theHandVariable = gameObject.transform.Find("Model1/Body2/Hand3").GetComponent("ScriptName").aVariable;

Once again, .Find and .Get functions are slow, cut out each one you can by storing in a variable!

Comment
Add comment · Show 3 · 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
avatar image vished · Feb 26, 2011 at 07:58 AM 0
Share

Interesting! Thanks for your input. Is there no way around using 'find'? I don't want to have to search for an object if I know it exists. I've read that searching with 'find' can slow down games. Is there no way to directly refer to a transform(game object?) component without searching for it? Does unity not keep track of what is in a scene? http://forum.unity3d.com/threads/67943-What-can-slow-down-your-games "Avoid slow functions (like FindObject)" Thank you

avatar image by0log1c · Mar 02, 2011 at 04:54 AM 0
Share

Slow reply,sorry. I also corrected the code a lil' bit. I'll also answer because I care: .Find functions are considered slow, the idea to avoid them is to use them once, then store the result in a variable. What's to avoid is to repeatedly .Find for a hand that most likely never changes. Using a variable is fine :)

avatar image vished · Mar 06, 2011 at 11:45 PM 0
Share

Thanks for your input BY0LOG1C - could you add the code for changing a variable that you deleted as a note? It was very useful and I didn't make a copy! I still can't believe you can't refer to elements without having to search for them. I guess the most efficient way is to have a public variable and drag and drop.

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

No one has followed this question yet.

Related Questions

Transform.gameObject References Itself?! 0 Answers

Why is there no gameObject.parent? 1 Answer

Selecting transform in FBX hierarchy csharp script 1 Answer

A GameObject That's Not Active In The Hierarchy Still Calling Its Start Method? 1 Answer

I want to move a cube with rotation but I find this problem 1 Answer


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