• 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 Ent · Jun 09, 2010 at 01:15 PM · gameobjecttransformif-statementsfindfind-gameobject

transform.find and Instantiate do not return the same type?

Hi, im using a Hashtable for storing new made objects and what groups they belong to. I have created a transform Object called 'Scene' before hand, w$$anonymous$$ch also belongs in the Hashtable. The 'Scene' is the main group, later sets will be added to the 'Scene' dynamically.

(dont t$$anonymous$$nk to much about the functions, Im still testing t$$anonymous$$ngs ;) )

function Start(){
var elemData : Hashtable = new Hashtable();
elemData["Transform"] = transform.Find("Scene");

Debug.Log("found:"+elemData["Transform"]); //contList.add(parentObject); <-- the later statement works with var parentObject : Transform; //contList.add(elemData["Transform"]); <-- the later statement doenst work contList.add(elemData);// <-- the later statement doenst work }

the add function exists as add(hashtable) and add(transform), the add(transform) just calls the add(hashtable) variation.

After t$$anonymous$$s I add the Objects to the game (at the moment just by pressing fire, later over user clicks and a database)

function Update () {
if (Input.GetButtonDown("Fire1")){
    //var newobj:transform = Instantiate(newObject, transform.position,transform.rotation);
    var elemData : Hashtable = new Hashtable();
    elemData["Position"] = new Vector3((modWidth*counter*scale),0.0,(modHeight*0.5*scale));
    elemData["Scale"] = new Vector3(scale,scale,scale);
    elemData["Color"] = new Color(0.5,0.5,0.5,1);
    elemData["Translation"] = new Vector3(0.0,0.0,0.0);
    elemData["Angle"] = new Vector3(270.0,180.0,0.0);
    elemData["Transform"] = Instantiate(newObject,Vector3.zero,Quaternion.identity);
    //elemData["Transform"] = parentObject; <-- Also works
    counter ++;
    contList.add(tmpcnt,elemData);//<-- T$$anonymous$$s works as well
    //contList.add(elemData);<-- t$$anonymous$$s works too
    if(counter%5==0)tmpcnt++;

Debug.Log(elemData["Transform"]); } }

The counter and tmpcnt is there for grouping only and testing. Now to my problem of understanding.

I am saving the gameObjects in a different class:

t$$anonymous$$s.container = elemData["Transform"];

and testing if the t$$anonymous$$s variable is set with following statement:

    if(t$$anonymous$$s.container!=null){...}

t$$anonymous$$s statement is only true when I either use a fixed variable pointing at the transform.Scene, create an object with Instantiate, but false when I use transform.Find. All 3 variations are Objects or not? Later I will be finding the sets dynamically over the name, so I will be using the find, but if t$$anonymous$$s doesnt work, then I will need to plan somet$$anonymous$$ng else. I wasnt sure if it had somet$$anonymous$$ng todo with gameObject and transform, but converting the find result into a gameobject/transform didnt help.

I do hope someone can clear my misunderstanding on t$$anonymous$$s point

thankyou Ent

Comment
Add comment
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

1 Reply

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

Answer by dhendrix · Jun 09, 2010 at 01:20 PM

Transform.Find returns the transform of the gameObject, w$$anonymous$$le Instantiate returns a reference to the gameObject itself. To compare them you should do transform.Find("whatever").gameObject.

Comment
Add comment · Show 1 · 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 Cyclops · Jun 09, 2010 at 01:33 PM 0
Share

+1. This trips up people a lot - the relationship between a Transform and GameObject, and when each is used, isn't immediately obvious (at least it took me a while to figure it out, but maybe I'm just slow. :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

This does not make sense this.gameObject.transform.Find() why? 2 Answers

Convert a GameObject to a transform? 1 Answer

Find Gameobject Transform, dont work now? 3 Answers

GameObject.Find("something")..how to use with transform,audiosource and texture ? 1 Answer

Which is faster, GameObject.Find or GameObject.FindWIthTag? 2 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