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 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, which also belongs in the Hashtable. The 'Scene' is the main group, later sets will be added to the 'Scene' dynamically.

(dont think to much about the functions, Im still testing things ;) )

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 this 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);//<-- This works as well
    //contList.add(elemData);<-- this 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:

this.container = elemData["Transform"];

and testing if the this variable is set with following statement:

    if(this.container!=null){...}

this 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 this doesnt work, then I will need to plan something else. I wasnt sure if it had something 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 this 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, while 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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Finding object with transform 1 Answer

Find Transform in the scene 2 Answers

How to get the objects inside another object and put them in a array? 1 Answer

Why does this wont work? transfor.find() 1 Answer

Why is the rotation values I am accessing wrong? 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