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 siddharth3322 · Jul 10, 2017 at 10:44 AM · programmingfollowscritpingorder-of-execution

Same script execution order issue

Basically I want to know about script execution logic. At present same script added into 5 different game object but script is not executing in sequence though object exist in game in sequential order.

Here is script execution order reference image: alt text

I want script to be executed in 1 to 5 order as like their object created/arranged in hierarchy. So please share your thought regarding this.

scriptexecutionorder-issue.png (56.4 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 SohailBukhari · Jul 10, 2017 at 02:26 PM 0
Share

Script Execution Order Settings https://docs.unity3d.com/$$anonymous$$anual/class-ScriptExecution.html

avatar image siddharth3322 SohailBukhari · Jul 10, 2017 at 02:48 PM 0
Share

Here we are talking about same script execution order on multiple objects. I want that in a particular order.

1 Reply

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

Answer by DaDonik · Jul 10, 2017 at 10:50 AM

I assume you are using the Update method to print to the console. There is no guarantee in which order any of your scripts will be updated.

What you can do is to create a new script, called TailHandler for example, which holds references to your other scripts. Simply rename the Update method of your current script and invoke that method from the TailHandler. Now you are in charge of the execution order!

Comment
Add comment · Show 5 · 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 siddharth3322 · Jul 10, 2017 at 11:07 AM 0
Share

So as per your saying I have two ways for solution, i) use different script for execution ii) use one update method and then call all child object code from that

basically each attached node contains same script to follow the upper node so what is better approach?

avatar image DaDonik · Jul 10, 2017 at 12:05 PM 0
Share

In the end the right solution is the one you feel comfortable with. Personally i don't like to be dependent on the hierarchy, except for UI elements, but that is mostly a personal preference.

avatar image siddharth3322 DaDonik · Jul 10, 2017 at 12:13 PM 0
Share

Basically I thought like that each child node have script which doing task of following its parent node so in this case execution order matter otherwise you will see a gap between some child nodes.

avatar image DaDonik · Jul 10, 2017 at 12:32 PM 0
Share

Are you making a snake clone?

Then it would make most sense to have a handler script that has a list of references to all the nodes. I would assume that each node has a reference to it's parent and one to it's child.

  1. Iterate over the list and update each node.

  2. Add new nodes to the back of the list, which will automatically make them update in the right order. Set the parent of the node to the previous element in the list and set the child to null.

  3. When removing a node somewhere in the list, remember it's parent and child nodes. Then access the parent and set it's child node to the one you remembered.

What you need is pretty much a linked list. You can look that up on google. There should be plenty of examples of linked lists in C#.

avatar image siddharth3322 DaDonik · Jul 10, 2017 at 02:11 PM 0
Share

Now I think simplify above of your answer after seeing my question properly so I can make this correct and become helpful to others.

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

71 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

Related Questions

Multiple Cars not working 1 Answer

problem with scripting 1 Answer

looking for DOTS study materials 0 Answers

Camera rotation around player while following. 6 Answers

Why the state of the member array of the class isn't maintained outside the function it is initialized in? 2 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