Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by Klies · Apr 30, 2010 at 07:58 AM · instantiatescaleparentchild

How can I Instantiate a clone as a child of another object, and inherit the parent object's scale?

I currently have a Laser/Mirror puzzle that relies on cloning laser objects to simulate the bouncing of light off of mirrors. The way that this is being done is with a call to Instantiate of an object that is already contained in the hierarchy of the "laser projector" object.

However, the laser projector object has a scale factor set that I need to be applied to the newly cloned object which should then be added as a child of the projector. There are a couple of ways I can do this that I know of. I can either traverse the hierarchy and multiply the scale factors together, since I know how high the hierarchy is and it won't change. I could also hard code the scaling factor into the clone, since I know what is, however it may change and that isn't very modular.

I would really like to just be able to instantiate the new laser as a child of the projector and have it receive the scaling factors through the hierarchy though. I can't find a clean way to do this in the documentation, and it seems like the only way to parent something is to set its transform.parent after the object has already been made and added to the root of the scene hierarchy. This means that when the parent of it is eventually set, there's no way that the nested scaling factors will be transferred to the new lasers.

Is there a nice way to do what I'm trying to do?

Thanks.

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

2 Replies

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

Answer by duck · Apr 30, 2010 at 08:02 AM

After you have set the object's transform.parent, set it's Transform.localScale to 1, 1, 1:

newInstance.transform.parent = parentTransform;
newInstance.transform.localScale = Vector3.one;

Because it has a local scale of 1 in all axes, its size will directly reflect its parent scale transformation.

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 Klies · Apr 30, 2010 at 08:22 AM 1
Share

worked perfectly. Thanks for the prompt response.

avatar image Narven · May 14, 2010 at 08:41 AM 0
Share

i have someting like this:

for (int i = $$anonymous$$Clones; i < maxClones; i++) { Instantiate(master, RandomPosition(), Quaternion.identity);
}

master is a prefab... how do i make it child of the transform?

avatar image Wolfram · May 25, 2011 at 10:09 AM 1
Share

Please no new questions inside answers, especially if they are only marginally related.

Store your instantiated object in a local variable (C# example):

 GameObject newObj=Instantiate(.....) as GameObject;
 newObj.transform.parent=transform;
avatar image
0

Answer by Cjj · Jul 09, 2010 at 04:46 PM

Use Object.Instantiate(). http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html

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 SrBilyon · Nov 29, 2012 at 10:58 AM 2
Share

Best Answer I've ever seen ;)

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

2 People are following this question.

avatar image avatar image

Related Questions

Make a simple tree 1 Answer

make a child always have its own scale? 7 Answers

Phonton: Clients do not see child/parent relationships 1 Answer

Basic question about Parent-Child and Instantiation 1 Answer

[SOLVED] How to make to clone an object and make it parent of the transform? 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