• 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
Question by kag4380 · Nov 27, 2014 at 08:23 PM · different objects

change values after all update function of multiple objects of same script is called

So, I have been instantiating a gameobject with a script attached, say S, to it. Each gameObject I instantiate is having different name. The Script S attached to each of this gameObject has three variables row, column & name. I know that the order in which these objects re instantiated will have their Update function executed first. Scripts S's Update function makes some modifications to these variables but since the execution is not simultaneous & an update of one affects the update of other.

For example : I have instantiated a gameobject A with script values : row=2, column = 1, name = A & then instantiate another gameobject B with row=2, column=3, name = B. Update function of A changes row to 1 & column to 3 & Update of B changes row to 3 column to 0. What i want is to send the values of row & column to another script. But, since B gets executed after A, values sent by A gets overwritten by values sent by B.

I want to know if their is a way by which I can write a function after all the updates of same script(but different objects) have been executed?

Thanks in Advance!!

Comment

People who like this

0 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 NoseKills · Nov 27, 2014 at 10:45 PM 0
Share

I'm not getting what you want the execution order to be finally.

Could you just pass the variables to the "another script" (X) by calling a method in it and on top of taking in the values, that method would do all the necessary actions with those variables. Since each "S" calls that function, X will perform the necessary actions with all the values passed from all instances of S.

If X does something where it needs the info from all instances of S simultaneously to make the necessary actions, then you'll just have to make X collect a list of parameters and keep track of how many Ss have run their Update and do what needs to be done after they all have Updated

avatar image kag4380 · Nov 28, 2014 at 12:44 AM 0
Share

Sorry for the ambiguity in question. Let me keep it simple this way. How to run a function after update function of all the objects with same script is completed?

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Kiwasi · Nov 27, 2014 at 10:53 PM

Try LateUpdate. LateUpdate is designed for things like camera movement that must happen after all other scene movement.

Note that relying on scripts to execute in the order they were instantiated is asking for trouble. There is no guarantee this will work on any particular build platform, or that this behaviour won't change in the future.

Comment

People who like this

0 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 kag4380 · Nov 28, 2014 at 12:43 AM 0
Share

LateUpdate is called just after Update. So if you have multiple objects with same script, it will call update & late update of one script & then move to next script for doing the same. What I want is, to write a function that I can call once update function of all the scripts is complete.

avatar image Kiwasi · Nov 28, 2014 at 02:15 AM 0
Share

In that case you are better off with a Manager. Maintain all of the scripts in a List. Call your own update method on each of them from your manager. Then call your function.

This method also gives you a firm guarantee on the order of calling.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

different objects with the same script wouldn't react correctly 1 Answer

Calling a function from same script, on different objects, through Inspector. 2 Answers

Is bug in unity?position error at some place on screen 0 Answers

I can't change a boolean from another script on another object from my script 1 Answer

Multiple GameObjects with the same script all react but I only want one at a time. 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