- Home /
prefab: can you exclude a variable from beign tracked?
Can I exclude the scale of a prefab instance from being tracked? Unity already allows prefab instances to have independent rotation and position, can I exclude the scale likewise?
An example: Imagine I have a prefab of a tree that has built in functionality for my character to interact with. My scene takes place in a forest, so there are lots of trees... each tree is an instance of a prefab, and for design reasons, each has a different scale (carefully placed).
Imagine I decide to improve my tree prefab. Thing is I'd have to write some code to reset every prefab of every scene, and I have to make some script to store a scale, and call it whenever the prefab is updated. Both of this I can do with the PrefabUtility, I'm just wondering if there's a better way, and I can just exclude the scale or other variables
How is your tree script structured? Are you using inheritance/composition? Tree is too abstract, so you would usually make it an abstract class and then different kinds of trees like maple tree would derive from tree. Prefabs are just like templates, you define a base template, attach a behaviour to it then instantiate and if there is a need you can modify stuff at runtime. You could also look at composition, so ins$$anonymous$$d of tightly coupling tree's functionality, for specific functionality you could use interfaces.
$$anonymous$$aplica, thanks for answering. I guess my example was misleading. There's no prefab tree I have. $$anonymous$$y question is more of an hipotetical nature. I just want to know if it's possible to somehow stop tracking some variables from a prefab. $$anonymous$$any times already I found my self saying: "jeez, I wish there was a way to stop the prefab from updating just this particular variable". So I wanted to see if there was someone in this great comunity that may know how to do that.
The OP isn't describing a component for trees. They're describing a scene with several copies of a single Tree prefab where they want to change a single value on that prefab, propagate that change across trees in the scene, and leave other values the same.
If you cannot find a way to change a single value, you could always write an editor extension to do so for trees in your scene.