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
2
Question by BrotherB · Jan 12, 2012 at 02:21 AM · instantiateprefabblenderscale

Instantiated prefab scale is wrong.

Hello, and I hope my first question here hasn't been answered in a million places, I have been looking all day.

I have a project that instantiates a prefab (sol1) through a script using this code.

 var sol1 : Transform;
 var a1s = Instantiate(sol1, Vector3(0, 0, 0), Quaternion.identity);

This code was directly lifted from another project and works famously, but when used in this project the prefab is instantiated with the wrong scale, usually 0.999999 something on all axis. This does not happen in any of my other projects, where prefab scale is simply carried over into the scene. I don't understand why this happens here. Also, trying to access the scale to change it after it is instantiated has no effect. I have tried instantiating it to the position and rotation of an empty, but it is the same. It seems everything does what it is supposed to, except it refuses to keep the prefab scale and let me access the scale after the object is spawned. I have also tried this with two versions of the prefab, one off the project list and one out of the scene itself, with no difference. Bringing in and using a prefab that worked in a separate project with this code resulted in two out of three axis over-scaling incorrectly with the third scaled down to 1.

I am unbelievably lost in what looks to me like random behavior in Unity and I have no idea what to try next beyond just scrapping it and starting over. Please help!

-Brother B

I found the problem, and I feel like such a moron. The problem is with Blender 2.61, not Unity. I tried all sorts of ways to modify and re-export the objects with no luck. I opened a new Blend file, made a new object from scratch, and exported it into the project. It too had the scaling problem. Finally, I gave up, and as a last ditch attempt I re-opened my original model in Blender 2.59 instead of 2.61 and exported it one last time, this stopped the forced rescaling.

I'm really happy to know I'm not crazy and I would like to say that I LOVE Unity and was perfectly willing to do what it takes to work around this if necessary. Thanks, everyone, for helping out.

-Brother B.

Comment
Add comment · Show 6
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 rabbitfang · Jan 12, 2012 at 04:30 AM 0
Share

How are you finding that the scale is .999..? Where does it say this?

avatar image luizgpa · Jan 12, 2012 at 06:53 PM 0
Share

Can you see any visual difference (0.0001% error)?

It's because the way real numbers are calculated in computers. http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding

avatar image BrotherB · Jan 12, 2012 at 07:56 PM 0
Share

The scale of .999999 is shown in the Inspector under scale, where I can see the difference between the original prefab and the Instantiated version. Also, yes, there is a visual in scene difference, that is how I first noticed. What is interesting is that I can drag the prefab out into the scene and it scales fine in accordance with the prefab scale, but when Instantiated it's very tiny by comparison.

avatar image Kryptos · Jan 12, 2012 at 09:04 PM 0
Share

It cannot be tiny because of a scale of 0.9999999. Because of floating point precision, there is no difference between 1.0 and 0.9999999.

avatar image BrotherB · Jan 12, 2012 at 09:36 PM 0
Share

The prefab is scaled to 10, 10, 10. This is not being maintained when Instantiated.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kryptos · Jan 12, 2012 at 10:20 PM

One important thing to know is that any change to the transform of an instance prefab will not be reflected on the original prefab when clicking on "Apply". This can be easily understood: while you want all your instantiated prefabs to share every components and parameters, you may want to have them at different place/size/rotation without breaking prefab connection.

  1. Verify that your prefab (not an instance of this prefab in your scene) scale is indeed (10, 10, 10).

  2. Try to instantiate your prefab using the method with one argument only (although I'm pretty confident that the other one will still work).

I did some test. It worked fine for me.

Comment
Add comment · Show 2 · 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 BrotherB · Jan 12, 2012 at 11:03 PM 0
Share

It is indeed 10, 10, 10, as seen from the Project Tab itself. I created a new script and a new test scene, using the following code attached to the main camera, the only object present.

var thing1 : Transform;

function Update () {

if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.S)) { var t1 = Instantiate(thing1); }

}

The result is that the scale of the instantiated object is now 0.9999998, 0.9999998, 1 as in the original scene.

It also changes the prefab rotation from 0, 0, 0 to -4.242594e-06, 8.439047e-07, 348.75 (but that's a whole 'nother road of crazy I didn't want to go down yet)!

What I just noticed is that if I drag and drop the prefab from the Project window to the scene, the scale is 10, 10, 10 UNTIL I press Play, then it too rescales to 0.9999998, 0.9999998, 1. This is without pressing the S key or doing anything else once it starts.

There is a difference though in this scene than in my original. I have another prefab with a scale of 30, 30, 30, that if I plug into thing1 in this test scene spawns without rescaling. However, in the original scene it too would be rescaled, only to 100, 100, 1.

I feel like what I am typing is madness and you're all sitting back shaking your heads solemnly at my mental illness! Or worse, looking for hidden cameras.

avatar image Kryptos · Jan 13, 2012 at 12:03 AM 0
Share

Upload an (reduced) example of your project somewhere so we can help you.

$$anonymous$$y guess is you have another script rescaling everything (or some object of some type).

I didn't find any camera. But that's the purpose of hidden cameras: they are hidden O_O'

avatar image
0

Answer by ematsuno · Mar 22, 2018 at 04:06 PM

I ran into the same situation when I instantiated a prefab with several images.

For some reason, the background did not scale correctly, but everything else did.

None of the advice above worked, however, this worked for me.

Save the prefab as inactive. After instantiating the game object, instantiate it.

Thus:

//Make sure the prefab is not active public GameObject currentBackground = null; public GameObject prefab; public GameObject template; // placeholder for object

     currentBackground = (GameObject)Instantiate(prefab);
     if (currentBackground != null)
     {
         currentBackground.transform.SetParent(template..transform.parent, false);
         currentBackground.transform.position = template.transform.position;
         currentBackground.SetActive(true);
     }
Comment
Add comment · 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

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

9 People are following this question.

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

Related Questions

How do I scale an object or prefab to a size in Unity units? 1 Answer

Prefab instantiated wrong scale on mobile 0 Answers

Instantiate prefabs scaled 1 Answer

When I instantiate a 2D bullet it's BoxCollider2D fails verification. 0 Answers

Instantiating Cube Prefabs with scale 3 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