Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by tomekkie2 · Jan 11, 2013 at 08:35 AM · orderexecution

Manage the script execution order, how?

I have a parent object contain several child objects with the componet scripts attached. Those component scripts execute in the child objects scene sequence of order. I need to sort (z-sort) that order at runtime basing on the current child distances from the camera.

Comment
Add comment · Show 13
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 asafsitner · Jan 11, 2013 at 09:31 AM 1
Share

Don't use Update on the children, then, and ins$$anonymous$$d implement your own manager on the parent that calculates priority and calls the necessary methods on the children?

avatar image tomekkie2 · Jan 11, 2013 at 10:09 AM 0
Share

Not exactly. I want to controll the execution sequence of the onGui function. I am writing a script to controll the gui depth, but I was just wondering if that could be somehow done by sorting the script component

avatar image asafsitner · Jan 11, 2013 at 10:17 AM 0
Share

I don't believe you can sort the components at runtime.

avatar image tomekkie2 · Jan 11, 2013 at 10:40 AM 0
Share

And control the scripts execution order on siblings? If so the depth method is the only option in my case.

avatar image Wolfram · Jan 11, 2013 at 11:03 AM 2
Share

An alternative to UnityGUI would be to use actual 3D objects (=regular scene objects) for your interface. With a billboard class, you can ensure any planes or Text$$anonymous$$eshes are aligned to the camera and are perceived as 2D elements, but any sorting and visibility/occlusion (especially with other scene objects) will be handled by the normal rendering process.

As long as you don't need specialized, complex GUI functions, this is usually the best approach.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cregox · Jun 11, 2013 at 05:45 PM

There are at least 2 questions here. About the implicit GUI z-order one, I think it is mostly already answered on the comments: just have a OnGUI manager which will call your own DrawGUI on each component.

Now, for executing child objects in script based on distance from camera, you could do something like this (unverified code):

 using System.Collections.Generic;
 
 class whatever : MonoBehaviour {
     public Transform parentOfCameraChildrenObjects;
     private List cameraChildrenObjects = new List();
     
     void Start ()
     {
         int i = -1;
         Vector3 cameraPos = Camera.main.transform.position;
         
         cameraChildrenObjects.AddRange(
             parentOfCameraChildrenObjects.GetComponentsInChildren()
             );
         
         cameraChildrenObjects.Sort( (x,y) =>
             Vector3.Distance(x.transform.position, cameraPos) >
             Vector3.Distance(y.transform.position, cameraPos)
             );
     }
     
     void Update ()
     {
         foreach (Transform child in cameraChildrenObjects)
         {
             child.SendMessage("MyMethod", "my string as parameter");
             // or
             child.GetComponent().MyMethod("my string as parameter");
         }
     }
 }
Comment
Add comment · 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

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

13 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

Related Questions

How to check execution order from script? 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Destroyed object is still registering a trigger event 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 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