• 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 assuming 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Transform constant moving in scene even if translated for Vector3.zero 1 Answer

Car Controls without physics. 1 Answer

Unet Spawn Prefabs When Scenes Changes 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges