QUESTIONS
How can I change prefab values in code correctly?
Can I overwrite member values of prefabs with scripts?
Is it possible to record overwrites of prefabs for the undo manager?
How can I permanently set values of prefab components?
LINKS -
Use Undo to record the change.
Call the PrefabUtility to record the modification
Code Snippet:
using UnityEngine;
// Only in the editor, not on run time
#if UNITY_EDITOR
using UnityEditor;
#endif
public class Changer:MonoBehaviour
{
public void ChangeValueOfPrefab()
{
// Only in the editor, not on run time
#if UNITY_EDITOR
var changing = GetComponent<Transform>();
Undo.RecordObject( changing, "Changing stuff" );
changing.position = Vector3.zero;
PrefabUtility.RecordPrefabInstancePropertyModifications( changing );
#endif
}
}
APP | VERSION Unity 2022.1
QUESTIONS
How can I change prefab values in code correctly?
Can I overwrite member values of prefabs with scripts?
Is it possible to record overwrites of prefabs for the undo manager?
How can I permanently set values of prefab components?