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 /
  • Help Room /
avatar image
1
Question by $$anonymous$$ · Jul 25, 2016 at 01:39 PM · transformlocalscale

LocalScale not working?

Hello,

I know there are a lot of topics about localScale but I assure you, I can't find an answer to my problem. So it's the first time I use localScale and I want to modify the scale of an object (duh). Here's my code:

 public void ResetStarsParameters() {
             Debug.Log(_variables.FolderStar_1.transform.localScale);
             Vector3 scale = _variables.FolderStar_1.transform.localScale;
             scale.Set(1,1,1);
             _variables.FolderStar_1.transform.localScale = scale;
             Debug.Log(_variables.FolderStar_1.transform.localScale);
             Debug.Break();
             //_variables.FolderStar_1.transform.localScale += new Vector3(1, 1, 1);
         }

I tried the same thing with the code on the commented line (it was what I first wrote before looking on internet), even with or without the + sign before the = sign, same result.

In the player, nothing is happening and neither in the inspector:alt text

But when I take a look at the console, everything is working perfectly fine:alt text

Am I missing something?

Thank you for your help!

EDIT: By the way I added Debug.Break() to check whether or not the values were changing before I could see it & I forgot to say this code is happening on the last frame of an animation clip as an event. Might it be because an animation controller is attached to the game object this script is attached to?

inspector.png (12.7 kB)
console.png (9.9 kB)
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

4 Replies

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

Answer by $$anonymous$$ · Dec 15, 2016 at 01:11 PM

Unity contacted me and said: "After further investigation this turns out to be by design.

Unity intentionally doesn't let you change the value of a property you are animating.

What is happening here is you're changing the local scale value of your object, but since you're in play mode and the object is animated, it will be overwritten back to the animated value.

As a workaround I can suggest you to either implement it as an actual state machine state, or disable animator and gain back control on its object values."

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
avatar image
2

Answer by BrkTbn · Jul 26, 2016 at 11:23 AM

This code works.

 Vector3 scale = transform.localScale;
 
         scale.Set(4, 4, 4);
 
         transform.localScale = scale;

There is nothing wrong with your code. Just like you said, if your animation clip contains fixed frames of transforms and it overrides each frame, it might be setting your scale back to (0, 0, 0) after you modify it.

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 rizkyaakbar790 · Jul 07, 2019 at 07:47 AM 0
Share

unfortunately, $$anonymous$$e still didnt work

avatar image
2

Answer by kryzodoze · Nov 14, 2016 at 08:40 PM

I also just found out that if you have an animation anywhere within that object's Animator flow that alters the localscale then you won't be able to alter it.

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
avatar image
0

Answer by $$anonymous$$ · Jul 26, 2016 at 01:24 PM

Ok. That's true that there is an animator controller on the game object this script is attached to however the code does not modify this game object but another one.

UPDATE: Ok, so I tried something to try to understand why it's not working: instead of targeting my object "FolderStar_1" I decided to target some other objects. Here what I discovered:

. On objects with an animator controller attached to them, the code won't work (it's a bug and it's going to be fixed).

. On objects with or without an animation component attached to them it does work.

Comment
Add comment · Show 4 · 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 BrkTbn · Jul 26, 2016 at 01:42 PM 0
Share

O$$anonymous$$ I get it now but it's strange, there must be another script which sets the scale back to zero, either on the object you are modifying or elsewhere.

avatar image $$anonymous$$ BrkTbn · Jul 26, 2016 at 02:11 PM 0
Share

I was afraid that it could be the case that's why I added a Debug.Break() right after the code to see if the scale of the object was at least 1 in the inspector & player. But nothing, the scale stays 0 even right after the code as been executed. What's funny is that in the console it says the scale is 1 while clearly it's not. Could it be a bug from Unity? I came across a problem few months ago were I was stuck like that and it appeared to be a bug. I'm using Unity 5.3.3. I found a way anyway to not use this code but I would like to know what is the problem here =/

avatar image BrkTbn · Jul 26, 2016 at 02:19 PM 0
Share

Looks like a bug then, maybe you should contact Unity support :)

avatar image $$anonymous$$ BrkTbn · Jul 26, 2016 at 02:28 PM 0
Share

Ok, I'll do that then and keep you posted.

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

70 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

Related Questions

Saving default scale of an object c# 1 Answer

Change transform on ChildObjects except one 0 Answers

transform.localScale in Coroutine grows exponentially 0 Answers

objects of same parrent random scale/size(xy and z) 0 Answers

Unwanted Decimal Value When Scaling Object 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