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
0
Question by rookiemistakes · Jan 26, 2016 at 04:34 PM · transformprefabrigidbody2dtranslateinstatiate

Can't move instantiated object.

Hey guys,

I've got a instantiated object/prefab and I can't modify it's position.

Here is a code snippet (in a script outside of the prefab):

             for (int i = 0; i < protags.Count; i++)
             {
             protags[i]._sprite = Instantiate(Resources.Load("Demon"),
             new Vector3(0, 0, 0), 
             Quaternion.identity) as GameObject;
             }

         foreach (Protag ptag in protags)
        {
         **Vector3 theScale = ptag._sprite.transform.localScale;
         theScale.x *= -1;
         ptag._sprite.transform.localScale = theScale;**

         Vector3 thePos = ptag._sprite.transform.position;
         thePos.x = 200;
         ptag._sprite.transform.position = thePos;
         }

The only modification that seems to work is manipulating the object's scale (in bold). Everything else doesn't yield any results, I've tried many methods such as modifying the position, localPosition, Translate, adding force to it's Rigidbody2D, using a script inside the prefab.

Any advice would be perfect. Thanks.

Comment
Add comment · Show 3
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 itsharshdeep · Jan 26, 2016 at 05:55 PM 0
Share

Hi,

I m assu$$anonymous$$g the basic mistakes here like the script is not attached or not enabled 2) $$anonymous$$ay be object is marked as static (a check box present at top right corner in inspector ) These are two basic issues by which you are not able to move ...

By the way, have you debugged your code by placing logs ??? What is the result for the same

avatar image rookiemistakes itsharshdeep · Jan 27, 2016 at 01:29 AM 0
Share

Thanks for the advice, I'll cross check with your answer. Also I forgot to mention I put debugs before and after the position change and it outputted that the position was changed, but not visually with the object.

avatar image rookiemistakes itsharshdeep · Jan 27, 2016 at 01:53 AM 0
Share

Checked those two suggestions. I have a separate script that instantiates the object then modifies it. Objects that are already in the scene can be transformed fine, it's just with instantiated objects that it doesn't seem to work.

1 Reply

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

Answer by rookiemistakes · Jan 27, 2016 at 03:05 AM

Okay found out the solution, it was the Animator component causing issues. I encased the object in a another blank GameObject and edited the Transform of that. Not sure WHY it wouldn't accept my previous modifications, must be a bug.

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 Refzlund · Oct 16, 2016 at 07:46 AM 0
Share

Same problem. Thanks for timesaving

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

42 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

Related Questions

rotate object2d the direction it is moving? 0 Answers

Move GameObject with transform.position 1 Answer

Unet Spawn Prefabs When Scenes Changes 0 Answers

How do i move a cube by one of its Vertices/Vertex 1 Answer

The Unity version determines the hierarchical order of the Scenes 0 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