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
0
Question by med9bob · Feb 03, 2019 at 10:28 AM · instantiatescale

child instantiation and scale problems

Hi, I'm having a problem with Instantiating a new game object, so my problem is that the game object I'm trying to instantiate wich is a child of another game object, doesn't spawn in the right position exept if I set the scale of the parent to the initale value wich is 1,1,1. I already have a solution wich is modifying the size of my Go in photoshop instead of changing their scale in unity but I think that is not very recomanded and I'm sure it will cost me a lot of time later. thanks in advance

Comment
Add comment · Show 2
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 MansoorAhmadKhan · Feb 03, 2019 at 10:44 AM 0
Share

do not set parent while instantiating. after you instantiate assign the parent. it wont change the scale then

avatar image med9bob MansoorAhmadKhan · Feb 03, 2019 at 11:06 AM 0
Share

actually that is not an option for me because I attend to apply my script to a lot of parents and the position where the childs will be instatiated at is relative to the parent's centers and not the global center so I want to benifit this advantage to optimate my game and more. this method will give me the posibility to spawn the childs in the positions I want using the same position coordinations all I have to do is to apply the same script to all parents.

1 Reply

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

Answer by tormentoarmagedoom · Feb 03, 2019 at 11:46 AM

Good day.

Reading your Q and your Comments..

You always have 2 options to instantiate a object that will give differents final scale. Find your best.

Instantiate the object without parent, and then change its parent. This way the object will mantain its initial global scale.

Instantiate the object directly as a child of another, will directly apply the scale of the parent as reference, Its global scale will be this Vector3 parentLocalScale*ChildLocalScale

In the other side, you have the final position. The final position is always the same if you takea s reference the parent, so depending on what method from above you chose, you will need to correct the position after Instantiate/ParentSet.


Doing something like this will give you control of final scale and final position. Object will be the same global scale its stored as prefab.

 GameObject NewObject = Instantiate (Object, position, rotation);
 NewObject.transform.parent=ParentObject;
 NewObject.transform.localPosition = PositionInParentReference;
 NewObject.transform.rotation = RotationInParentReference;


Doing something like this will make the prebaj automatik change globalscale in reference of parent scale in ordeerr to mantain its own localsclae (Object global scale will be Vector3 parentLocalScale*ChildLocalScale)

 GameObject NewObject = Instantiate (Object, ParentObject);
 NewObject.transform.localPosition = PositionInParentReference;
 NewObject.transform.rotation = RotationInParentReference;

Bye!

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 med9bob · Feb 04, 2019 at 12:56 PM 0
Share

thanks man that helped me finding what I need

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

122 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make an object scale indefinately on key press? 3 Answers

Instantiating Cube Prefabs with scale 3 Answers

Get scale of instantiated prefab and resize 1 Answer

Instantiated prefab scale is wrong. 2 Answers

Instantiate prefabs scaled 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