• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Bluk · Aug 03, 2012 at 09:21 PM · transformhierarchylocalscaleincrease

Transform.localScale in a hierarchy seems to be working sporadically

Hi,

I'm having some troubles while trying to set the scale of some objects at runtime. I have this gameObject hierarchy (for instance) loaded at runtime:

 ToplevelObject
    |
    --- SectorObject1
    |   |
    |    --- ...
    |
    --- SectorObject2
 

I'm trying when the objects are loaded with the right scripts and textures etc, to change their scale. So I made a button to do so:

 if (GUI.Button(new Rect(20,140,100,40), "Increase Scale"))
     {
     var sector:GameObject = GameObject.Find("SectorObject1");
     sector.transform.localScale+=Vector3(1,1,1);
     }

Where SectorObject1 is in the hierarchy. The problem is that it doesn't work when i click several times, then it suddenly starts to work each time i press the button. However, when i make the same code but with GameObject.Find("TopLevelObject"), it works everytime...

So my question is:

What did I do wrong?

Cheers,

Bluk.

EDIT: Tried to access it in a different way:

  region.GetComponentsInChildren(Transform)[1].transform.localScale

Didn't work... Weird thing though, still works after clicking the button several times, and once it worked once, it works everytime.

EDIT2: Tried to make a coroutine that tries to scale every 0.1s until it works like this:

 function ScaleSectors()
 {
  var cpt:int = 0;
  var scaled:boolean = false;
  var trTab = GameObject.FindGameObjectsWithTag("sector");
  Debug.Log("Trying to scale");
  while (!scaled)
  {
  scaled=true;
  for (var tr in trTab)
      {
      if (tr.transform.localScale != Vector3(1f,1f,1f))
      {
      tr.transform.position=Vector3(0,0,0);
      tr.transform.localScale=Vector3(1f,1f,1f);
      scaled=false;
      }
      }
      cpt++;
      yield WaitForSeconds(0.1);
  }
  Debug.Log("Iterated "+cpt+" times");
 }

It iterates each time 91 times. Now i'm confused. It is not local to the scale only, it does this also with the position, and pretty much each attribute of transform. Still works everytime when i do it on the TopLevelObject.

Cheers :)

EDIT3: I've been wondering if the problem didnt come from the way i instantiate the object. The objects i instantiate like this won't scale as i want

 var sector:GameObject = Instantiate(Resources.Load(s.GetMesh()));

The objects i instantiate like this scales(and position) properly :

 var obj:GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);

Am i doing it wrong? :)

.

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
0

Answer by ThermalFusion · Aug 03, 2012 at 11:21 PM

If you don't use the exact name as in GameObject.Find("SectorObject1") I'm surprised it would work even once. Other than that it looks like it should work.

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 Bluk · Aug 04, 2012 at 11:28 AM 0
Share

This is just a typo. Actually the names are exactly the same in my code. I edited it to make it hopefully mor clear.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

What is the reasoning of multiplying by Time.deltaTime 1 Answer

Accessing children of instances vs children of original prefab 1 Answer

transform.localScale unexpected behavior after Rotate() 1 Answer

How to make an object's localscale values grow and shrink within a few seconds? 0 Answers

Resize object forward instead of along the z axis 4 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