Advertisement

Destroying GameObjects inside OnValidate

Started by July 13, 2016 01:13 PM
2 comments, last by Kylotan 8 years, 4 months ago

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?

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

Advertisement

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.

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.

This topic is closed to new replies.

Advertisement