#Change Mesh in editor when variable changed
1 messages · Page 1 of 1 (latest)
You can use the OnValidate method. This gets invoked whenever a serialized variable is changed in the editor.
public class ItemHolder : MonoBehaviour
{
[SerializeField] private Item item;
private void OnValidate()
{
// First check if "item" is null.
// If it is not, get MeshFilter component and apply item mesh.
// Potentially repeat for MeshRenderer.
// Or just spawn the Item's associated prefab as a child of the object (and replace existing children)
}
}```
Note that OnValidate will only be called on MonoBehaviours and ScriptableObjects (even though Intellisense may not auto-complete it for the latter).
Thanks friend