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 patrik-org · May 21, 2015 at 10:17 AM · c#gameobjectupdatelateupdate

Trigger LateUpdate on inactive gameObjects

I've been using LateUpdate() to do some update logic on my game-objects. The problem is that it doesn't get called on in-active objects which I need it to do. How can I work around this problem? Should I let another gameObject's LateUpdate() go through and manually call a "MyLateUpdate()" method on all the relevant gameObjects? Would it be a problem in terms of performance?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Halfbiscuit · May 21, 2015 at 10:27 AM

Why are you deactivating the object? If it is because you want them to stop rendering then you can just disable the renderer and LateUpdate() will still be called.

What you suggest would work and would not impact performance. But it could be irritating to set up and if you add more objects that you want to be called then you would have to add references to them.

I would suggest finding a way that does not involve deactivating the objects, just the other components on them perhaps.

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 patrik-org · May 21, 2015 at 11:31 AM 0
Share

Thanks for the suggestion. Disabling the renderer is probably the simplest solution for me.

avatar image patrik-org · May 21, 2015 at 04:59 PM 0
Share

Turns out it doesn't work for me as I'm working with UI gameObjects that doesn't have a renderer. They have a CanvasRenderer but there is no way to disable it :S.

avatar image
1

Answer by JCprogrammer · May 21, 2015 at 10:48 AM

I had the same issue though, my solution for it was something like this (Which might be like yours as well): Say you have specific type of objects that you want to update their properties even they are inactive. Call these type Foo, create a script then name it Foo. Then you will create a script called FooController. What this controller does, first it finds all the Foo typed objects in the field (the current scene), which can easily be done by FindObjectsOfType() function. Final step is to invoke the function you wanted to iterate as like LateUpdate() in a loop; Say we name this function FooLateUpdate(); in FooController's LateUpdate() function.

the implementation looks like this:

 class Foo
 {
      public void FooLateUpdate()
      {
        //some code
      }
 }

 class FooController
 {
        Foo[] fooObjects;
        void Start()
        {
                fooObjects = FindObjectsOfType<Foo>();
        }
        void LateUpdate()
         {
              foreach(var item in fooObjects)
              {
                        item.FooLateUpdate();
              }
         }
 
 }




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

21 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

Related Questions

Update character's position after animation 1 Answer

Multiple Cars not working 1 Answer

Make an array of all visible objects 1 Answer

C# Trouble getting object's current position on mouse down. 0 Answers

How to keep a Gameobject in the same position after a transform.Rotate? 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