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 elpuerco63 · Jan 29, 2015 at 09:08 AM · scripting problemgameobjectinstantiate

Tiny instantiated GameObject

I have a prefab that when I drop on my scene appears at exactly the correct scale, rotation and position.

I create an empty GameObject and copy the prefabs transform to it and call this empty GameObject SpawnLocation

I then delete the prefab from the scene.

In my script I have this code:

 GameObject obj = Instantiate(MyObject, spawnLocation.position, spawnLocation.rotation) as GameObject;

 obj.transform.parent = parentTransform;
 

MyObject is set to being the prefab I set in the editor and spawnLocation is set to the transform of the empty GameObject in the scene named SpawnLocation

parentTransform is set to the plane in the scene to which the instantiated object should be child to.

All good so far.....apart from the instantiated object appears in the correct place.....but is tiny?

It does not appear at the same scale as the prefab?

I drop again the prefab into the scene in the editor and it appears correct?

So how come I have an instantiated object of this prefab and using its same transform it appears so small?

Thanks

Comment
Add comment · Show 8
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 PorkMuncher · Jan 29, 2015 at 09:15 AM 0
Share

Weird, but just assign it's

 transform.scale=Vector3.one; 

before parenting it...

avatar image elpuerco63 · Jan 29, 2015 at 09:21 AM 0
Share

Hi,

Thanks..

there is no scale property so tried

 obj.transform.localScale=Vector3.one;

with no success :-(

avatar image GameVortex elpuerco63 · Jan 29, 2015 at 10:18 AM 1
Share

Remember to post comments as actual comments by using the "Add new Comment" button (I converted this one for you).

avatar image hav_ngs_ru · Jan 29, 2015 at 10:32 AM 1
Share

What are the parent transform values? if it has some not (1, 1, 1) scale - children inherit this.

avatar image elpuerco63 · Jan 29, 2015 at 10:38 AM 0
Share

hav_ngs_ru .... you hero :-)

Thanks, how do I accept your answer as the solution?

Thanks again ;-)

avatar image Glurth · Jan 29, 2015 at 10:43 AM 0
Share

If the parent transform is reducing the scale, the child object will appear small. (Though, I would have though assigning that transform as the parent would invert that in the localScale). $$anonymous$$aybe check the parent transforms for something like that? What happens if you don't assign a parent? (like when you drag it into the scene)

Show more comments

2 Replies

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

Answer by elpuerco63 · Feb 05, 2015 at 10:35 AM

and the resolution is:

currentPerson.transform.SetParent(obj.transform, false);

sorted :-)

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 Glurth · Feb 06, 2015 at 05:29 PM 0
Share

Face Palm All my stupid workarounds, and that function was there the whole time? Gosh, I need lessons how how to properly use DOCU$$anonymous$$ENTATION, lol.

(btw: if this WOR$$anonymous$$ED for you that would indicate you WERE setting the transform's local values BEFORE assigning the parent, not that it matters anymore.)

avatar image
0

Answer by SnStarr · Jan 29, 2015 at 01:27 PM

When you are instantiating the prefab onto the plane it is inheriting the properties of it's parent object which probably has a scale of less than 1 which is making the prefab also have a scale of less than one. Try resetting parents scale to one. Or setting the instantiated prefabs scale to 1 before parenting in script.

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 elpuerco63 · Feb 04, 2015 at 06:29 PM 0
Share

I thought I had this fixed, alas not and Im confused by it.

If I drag my prefab onto the parent object in the scene it appears in correct position and size.

The parent scale is 100,100,100 and when dropped the prefab scale is 1.942413, 1.942414, 1.942414

But if I instantiate the object and parent it alas it still appear tiny, even if I set the objects scale before setting its parent?

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

22 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

Related Questions

How can I spawn gameObjects within a circle radius? 1 Answer

How can I add the OnTriggerEnter function to all game objects that I instantiate? 1 Answer

Creating a GameObject variable without instantiating it? 1 Answer

LayoutKind.Explicit FieldOffset structs getting wrecked at Instantiate() 1 Answer

[Solved]Instantiating prefab from a script and destroy it from another one 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