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
0
Question by chillersanim · Feb 15, 2014 at 09:53 PM · c#meshrendererondisable

Get update calls from prefabs when they are changed.

[Update: See comment, renamed question for more accuracy]

Hello everybody
I have a confusing problem, probably a bug.
I've a script, that manages level of details. There is one script that manages the different lod-objects. When I deactivate this script, I want all lod levels to be visible. This script should also work in edit mode and has the [ExecuteInEditMode] attached.

I set the meshrenderer with the aid of a subroutine:

 private void SetMeshRenderer (GameObject obj, bool newState)
 {
     if (obj.renderer != null)
     {
         obj.renderer.enabled = newState;
     }
 
     for (var i = 0; i < obj.transform.childCount; i++)
     {
         SetMeshRenderer(obj.transform.GetChild(i).gameObject, newState);
     }
 } 

When I call this subroutine from the method "OnEnable()", everything works fine, the meshrenderers of the lod levels are updated correctly. But when I use this very same subroutine in the method "OnDisable()", then I get sometimes a bug.

When the script was deactivated from an object in the 3D scene (GameObject), everything works fine. But when the script was deactivated from the prefab in the library, then the meshrenderers are getting activated (checked with debuging...), but on the prefab and on the instances in the scene, nothing changes...

It's somehow difficult to describe, because I do not actually understand the problem myself...

Here's the code I use for the two methods:

 void OnEnable ()
 {                
     // Works fine here
     foreach (var level in LodLevels)
     {
         if (level.LodObject== null)
         {
             continue; 
         }
 
         SetMeshRenderer(level.LodObject, true);
     }
 }

 void OnDisable()
 {
     foreach (var level in LodLevels)
     {
         if (level.LodObject== null)
         {
             continue; 
         }
 
         SetMeshRenderer(level.LodObject, true);
     }
 }

Hope somebody is able to reproduce the error. If not, then I'm going to write an error report...

Greetings
Chillersanim

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 chillersanim · Feb 17, 2014 at 04:42 PM 0
Share

After some testing, I found out, that the prefab doesn't call the $$anonymous$$ethods from $$anonymous$$onoBehaviour (OnEnable, Update, etc.). Because of that, when activating/deactivating the prefab, his lod-objects don't get updated correctly and all instances just copy the object states.

So now I need to know, if there is a way to get if the prefab was changed or not (i.e. Is the changing object a prefab or a gameobject).

Has somebody an idea how to accomplish this?

Greetings
Chillersanim

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Feb 17, 2014 at 04:56 PM

Prefabs don't maintain a link to the instances when the game is running - so changing the prefab will not change anything. You need to change each individual instance of the prefab in the scene.

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 chillersanim · Feb 17, 2014 at 05:05 PM 0
Share

Yes I know, but because I'm working on a lod system that works also in the editor, I need to know when a prefab is updated. In the game, everything works fine, I only have problems in the editor.

Greetings
Chillersanim.

avatar image whydoidoit · Feb 17, 2014 at 05:09 PM 0
Share

Ah right that makes sense, well I don't think you can do that. You can tell if an instance is different to the parent, but I can't remember or find any documentation on a way of getting that as a prefab changed notification.

avatar image chillersanim · Feb 17, 2014 at 05:27 PM 0
Share

Hmmm, I will search a bit further. But in the meantime will I solve this problem with a force update button...

Greetings
Chillersanim

avatar image chillersanim · Feb 17, 2014 at 08:28 PM 0
Share

When I would use a custom inspector editor, would it be possible, that this custom editor can get the desired information?

If yes, then I could use that as solution, because the problem realy only occurs in the editor...

Gretings
Chillersanim

avatar image whydoidoit · Feb 18, 2014 at 12:50 AM 0
Share

You mean if it changes using a custom editor? Yes you could do that.

If you are only worried about your own fields then it would also be possible by using a checksum of the fields of the object done on a regular basis. UnitySerializer could compute you such a checksum.

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

19 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

If there is only 1 instance of a class, should it be Static? - C# 2 Answers

Call a Void on Collision 2 Answers

AI Patrolling 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