NEWS COMMUNITY STORE LABS UNITY UNITY QUICK TIPS (SCRIPTING) SIGN UP LOGIN LOGOUT ROKOJORI NEWSLETTER SIGN UP LOGIN LOGOUT NEWS COMMUNITY STORE LABS UNITY UNITY QUICK TIPS (SCRIPTING) TOGGLE FULLSCREEN VOLLBILD AN/AUS image/svg+xml image/svg+xml image/svg+xml PREFAB OVERWRITES
Save changes to prefabs from scripts
image/svg+xml image/svg+xml Save changes to prefabs from scripts image/svg+xml
quick-tip img:not(.icon) quick-tip img:not(.icon) quick-tip img[data-info] APP | VERSION
Unity 2022.1


RELATED TAGS
c#, code, script, scripting, prefabs, editor, undo, changes, overwrites


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


RELATED TAGS
c#, code, script, scripting, prefabs, editor, undo, changes, overwrites


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
-
TO UNITY QUICK TIPS






All social media brands are registrated trademarks and belong to their respective owners.





CONTACT IMPRINT TERMS OF USE PRIVACY © ROKOROJI ® 2021 rokojori.com
CONTACT IMPRINT TERMS OF USE PRIVACY © ROKOROJI ® 2021 rokojori.com
We are using cookies on this site. Read more... Wir benutzen Cookies auf dieser Seite. Mehr lesen...