Jump to content
  • Advertisement
Sign in to follow this  
rogerdv

Destroying GameObjects inside OnValidate

This topic is 881 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my game project, I want to let the scene editor build NPCs with modular body parts. The problem is that right now, they cant see the result until they run the scene. I tried to create some system to allow displaying the assembled model during edit time, but I found a problem: I have no way to rebuild it when some part is changed, because I cant destroy the previous GameObject inside OnValidate event. Is totally impossible to use Destroy or DestroyInmediate inside OnValidate?

 

Share this post


Link to post
Share on other sites
Advertisement

What do you mean by you "can't" destroy the previous GameObject inside the OnValidate event. What happens when you try?

Share this post


Link to post
Share on other sites

Im using an array of GameObjects to keep the meshes to build the character model. I wanted to update the model every time one of those elements is changed in the editor, but what I get is a mess of multiple instantiated copies and errors. Im thinking that my approach doesnt works.

Share this post


Link to post
Share on other sites

Okay. I'm not sure what the problem is but over at answers.unity3d.com it was suggested that OnValidate is the wrong place for that (because it's just for constraining the edited value to a certain range), and that you might want to use BeginChangeCheck to look for a change, and then do any object destruction based on that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!