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 CrPbI3yH · Aug 30, 2018 at 04:18 PM · instantiategameobjects

instatiated object don't get parameters

Hi everyone! I'm stucked. i'm creating instatiate of complex object and trying to set parameters from parent to childs, like:

main script:

 public static void some_func()
 {
 objects_list.Add(Instantiate(new_object)
 }

new_object script:

 void Awake()
 {
  some_static_parameter = 1;
 }

new_object_sub_object script:

 void start()
 {
  GetComponent<Rigidbody2D>().position = new vector2(new_object.some_static_parameter,0)
 }

And some time it works (3 object in a row created correctly), and some time it doesn't (4th will not get it), sub_object stay on default place. Can I use constructions as I mentioned, or it must be organized other way? I will really appreciate your help.

Comment
Add comment · Show 1
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 CrPbI3yH · Aug 30, 2018 at 08:39 PM 0
Share

Ok, i think i had identified the problem: if I change component to Transform then position change applies correctly. Still want to understand why it works in such way. Thanks in advance

1 Reply

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

Answer by JVene · Aug 30, 2018 at 10:47 PM

Based on your second comment, your original problem is solved but now you want to understand why the solution worked as it did, so here it goes:


The position of Rigidbody, documented here, is a way of informing the physics system of the new location you want, which is then used by the physics system to move the object's transform, in some way relevant to the physics being applied to the object. If your object doesn't use physics, then the Ridigbody.position would have no opportunity to alter the transform's position.


Ultimately, it is the transform that defines the position and orientation of the object. The Rigidbody is a means of getting the physic engine to move the object, where moving the object means updating the object's transform properties for position and rotation. When you switched to moving the transform's members, you went for that means of control compatible with the Unity engine design, but with caveats. If the object you're moving is also controlled by physics, altering the object's transform conflicts with the physics engine's control of that object (your code and the engine argue over that control). To solve that argument, Unity provides position in the Rigidbody so you have a means of providing some input to the physics engine for it's application of control over the object's transform. When physics is not used on the object, you can ignore the Rigidbody and merely use the object's transform.


In your case, however, it appears you had intermittent response when using Rigidbody.position. It is likely that there was some physics event happening coincident (and conflicting) with your expectation, because using position is not absolute positioning, it is relative to what the physics engine is doing to that object.


Typically, however, when instantiating new objects, you set the transform as a means of initialization. Your instantiation happens in a cycle of events where physics isn't going to have control of that object until after you've had the opportunity to initialize it, and that includes setting the transform's members, but for objects controlled by physics this is a one time opportunity. Once you 'let go' of the object within the Update or FixedUpdate function that instantiates an object, physics may take over, begin to control the object, and you should generally avoid using the transform for subsequent manipulation.

Comment
Add comment · Show 2 · 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 CrPbI3yH · Aug 31, 2018 at 01:38 PM 0
Share

ok, i understand the idea. so, now i just want to clarify. If i need to give to the just instantiated object both shift and speed, than i set postion change to transform and velocity to rigidbody. Is it correct? Can I do both operations in the same time or i need to use some kind of delay, coroutine etc?

avatar image JVene CrPbI3yH · Aug 31, 2018 at 05:40 PM 1
Share

You're correct, and for initialization they can be done at once.

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

170 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 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 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

destroying instantiated groups of objects 1 Answer

My programming says "The referenced script on this Behaviour (Game Object 'explosion_asteroid') is missing!" although my Scripts works fine. 0 Answers

Add Clones of GameObject to List(array) 0 Answers

Problem with Destroy function with instantiated Prefabs 1 Answer

Is it safe to instantiate a GameObject and then change it's components? 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