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 /
avatar image
0
Question by xpavelos · Jan 08, 2017 at 08:18 PM · instantiateinstantiate prefab

Object created through Instantiate does not update its position at the first frame

Hey all.

I have a small problem:

 SomeObject o = Instantiate(object_prefab, spawnPosition, Quaternion.identity) as SomeObject;

It creates the object as supposed, but the problem is - it's position is updated at the next frame. Basically the object is created at (0,0) position and in the next frame it is at "spawnPosition".

I had this problem in the past many times with different scripts and also it does't update rotation on first frame. Very frustrating. How to prevent it?

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 fafase · Jan 09, 2017 at 06:43 AM

You could explicitly set the position:

   GameObject o = Instantiate(object_prefab) as GameObject;
   o.transform.position = spawnPosition;
   o.transform.rotation = Quaternion.identity; // Not so useful since already set by default
Comment
Add comment · Show 10 · 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 xpavelos · Jan 09, 2017 at 01:33 PM 0
Share

Hey, of course I tried it before. It causes the same issue. The object will be at prefab's default position for just one frame and in the next frame will appear at the expected position.

avatar image jwulf · Jan 09, 2017 at 01:35 PM 0
Share

Just a wild guess, have you tried setting that in LateUpdate()?

avatar image xpavelos jwulf · Jan 09, 2017 at 02:14 PM 0
Share

Thanks for your suggestion. I haven't and I'd rather avoid that. I am relying too much on FixedUpdate() and moving to LateUpdate() would be very painful.

avatar image Fanttum xpavelos · Jan 09, 2017 at 07:14 PM 0
Share

your update might be running faster than your fixed update.

Show more comments
avatar image juicyz · Jan 09, 2017 at 07:21 PM 0
Share

This might work, as it will set it to inactive then change postions and what not then set it as active. At the very least, it shouldn't be visible... I also had a similar problem.

 GameObject o = Instantiate(object_prefab) as GameObject;
 o.SetActive(false);
 o.transform.position = spawnPosition;
 o.transform.rotation = Quaternion.identity; // Not so useful since already set by default
 o.SetActive(true);
avatar image xpavelos juicyz · Jan 09, 2017 at 08:12 PM 0
Share

Hey. I also tried this. I also turned off SpriteRenderer in a prefab, Instantiated the object, set it's position and then turn on SpriteRenderer and still have the problem.

avatar image juicyz xpavelos · Jan 09, 2017 at 08:33 PM 0
Share

Are you sure spawnPosition isn't (0,0)????? What is its value before the instantiate. The prefab object, what is its start, awake, onenable methods doing? What is its update method doing.

 SomeObject o = Instantiate(object_prefab, spawnPosition, Quaternion.identity) as SomeObject;

That line of code should work as is and put it in the right spot unless the spawnPosition isn't correct or maybe you are adding it as a parent to something and that's limiting it's movement?

avatar image hexagonius · Jan 09, 2017 at 07:44 PM 0
Share

this must be correct if called in Awake, Start or any Update. The moment it's called, it's there. If not something else is wrong.
setting the gameobject to any state is not necessary

avatar image xpavelos hexagonius · Jan 09, 2017 at 08:19 PM 0
Share

Any suggestion what else could be wrong?

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

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

Related Questions

Projectiles trigger affecting other projectiles of same prefab - C# 0 Answers

Animation doesn't affect the new instantiated object. 0 Answers

Why is it important to create an empty gameobject for my prefabs? 0 Answers

Instanciate prefab responsively 1 Answer

Show GUI Texture on Trigger and Instantiate Object if Button pressed while In Trigger? 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