This is comment for paste
MassPrefabRestorer
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- == Key Improvements ==
- * ObjectSnapshot Class: We now have a clean container that makes the code easier to read.
- ReplaceAndStopRecursion first "captures" everything in the snapshot and then "applies" the data.
- * Save Materials (Material[]): The snapshot now has a Materials field.
- It is populated only if a MeshRenderer exists on the original object, avoiding errors.
- We use the .materials property, which returns a copy of the array, ensuring the data is safe before the original object is destroyed.
- Safe Material Restore: Before applying the saved materials, the script checks two things:
- That the new prefab actually has a MeshRenderer.
- That the number of material "slots" on the new prefab matches that of the original object. This prevents errors and warns the user in the console if, for example, they are replacing an object with 3 materials with a prefab that only has 1.
- * Undo Integration:
- The material change operation is now correctly recorded with Undo.RecordObject, so you can undo it with Ctrl+Z.
- -- Last Edit:
- The system now is much smarter, avoid potential issue with Materials, and can restore the default materials from prefab if, for some reason they are missing.
Add Comment
Please, Sign In to add comment