• 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
1
Question by khandl · Dec 06, 2016 at 09:50 AM · rotationinstantiate-objects

Rotation of instantiated object is not applied

I instantiated object with this code:

  GameObject instance = Instantiate(playerCard, boardTransform.position, playerTransform.rotation, gameManager.getBoardHolder()) as GameObject;

On debugger looks everything OK, have correct values (Euler angels, rotation..): alt text

But on game scene is object on default (zero) rotation, the rotation argument does not affect the result. I tried put Quaternion.Euler() with different values, get transform and call Rotate or directly change euler angels but with no luck...

When i check object on inspector, it have zero rotation values.

alt text

I instantiated new object from existing one, not from prefab, and boardHolder is transform, which parent is Canvas.

What I am doing wrong? Thank you

EDIT: After some investigation I figured out, for some reason the instance lose its rotation. It's pity I'm not able to put data breakpoint to instance transform rotation, or cannot go to deeper due to lack of symbols and source code.

15356844-1517616634921524-708054865-n.jpg (49.7 kB)
15387581-1517613201588534-1306499400-o.jpg (368.2 kB)
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 AlwaysSunny · Dec 06, 2016 at 10:59 AM 0
Share

I'm not 100% sure this is your problem, but when instantiating canvas elements, I always do it in multiple steps. I can't quite remember why, but perhaps it's non-optional. Just to point out, instantiating from an existing object is almost never what you actually want to do (even when it seems like a good idea) so make sure there isn't a better approach.

 GameObject go = Instantiate( myObject ) as GameObject;  
 go.transform.SetParent( myCanvasOrSubObject, false );  
 go.transform.localRotation = whatever;
avatar image khandl AlwaysSunny · Dec 06, 2016 at 05:45 PM 0
Share

I tried set localRotation/rotation before and after SetParent() , like on your example, but without success. The object is still on the zero rotation. It's weird, because position works fine..

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by edcx · Dec 06, 2016 at 02:28 PM

Rotation you see in the inspector is local rotation and you are assigning a parent to your instantiated object. Your object's rotation and parent's rotation must be the same. That's why it appears (0,0,0).

Comment
Add comment · Show 3 · 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 khandl · Dec 06, 2016 at 06:11 PM 0
Share

Hmm, I didn't rotate my boardHolder (parent) and it have zero rotation. $$anonymous$$y instantiated object have zero rotation too on inspector. But you can see on debug watch, that my local rotation of instantiated object haven't zero value... Is there something i'm missing?

avatar image edcx khandl · Dec 06, 2016 at 06:45 PM 0
Share

Hmm, Have you also checked it's parent's rotation on debugger? What happens when you change the rotation argument in the instantiate function? Does it still 0? Can you check all the rotations when you debug next time? So we can see which rotation value is assigned in the instantiate, what is it's parent's rotation and what you get in the end.

Unfortunately, I couldn't think of anything else.

avatar image khandl edcx · Dec 06, 2016 at 07:08 PM 0
Share

When I set parent, only hierarchy and child count is changed. When I change rotation or local rotation it havent any result too.(In instance function or after instantiation). It looks like a Bug.

avatar image
0

Answer by Roixo · Jan 18, 2018 at 05:28 PM

Other simple way to solve this issue without creating empty parent game object:

 GameObject pc = (GameObject) Instantiate (Prefab, position, rotation, transform);
 pc.transform.Rotate (new Vector3(rotationWished.x,rotationWished.y,rotationWished.z));

Where you choose in Vector3 rotationWished which rotation you want.

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 Zergfx · Aug 02, 2020 at 04:37 PM

I had this problem. Switching the Render Alignment to Local in Particle System->Renderer solved it for me.

alt text


rotate.png (7.9 kB)
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.

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

Flip over an object (smooth transition) 3 Answers

Transform a Vector by a Quaternion 1 Answer

Have an object continuously rotate towards another 1 Answer

Character Controller slides sideways when it hits objects are angles different from 90 degrees 1 Answer

Move and Rotate object with "Parent" without Parenting 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