Clone vanilla UI more safely
Clone vanilla UI more safely
Section titled “Clone vanilla UI more safely”Before you use this pattern
Section titled “Before you use this pattern”This is not a beginner first-mod recipe and not a universal prefab-cloning API. Use it when you have already identified a specific vanilla UI object and need to reuse its visual hierarchy without blindly re-running copied behavior components.
Problem
Section titled “Problem”A vanilla UI object may look like a reusable visual prefab while carrying MonoBehaviour components that assume a very specific vanilla initialization context.
TerraForge cloned an active vanilla New World preset cell. The copied ButtonClickMaptemplate ran Awake() during Instantiate and threw NullReferenceException. A copied EventTrigger also retained unsafe vanilla tooltip behavior.
Safer pattern that worked in the case study
Section titled “Safer pattern that worked in the case study”1. temporarily deactivate the source vanilla cell2. instantiate the clone while the source is inactive3. remove copied ButtonClickMaptemplate4. remove copied EventTrigger5. keep visual Button / Image / layout components6. attach your own click handler7. use an already initialized vanilla path where needed8. activate the cleaned cloneGeneral rule
Section titled “General rule”Treat visual structure and behavioral components as separate things.
Do not assume copying a working GameObject means every copied component is safe to initialize again.
Version boundary
Section titled “Version boundary”The reusable lesson is the lifecycle pattern. The exact hierarchy, component names and “16 vanilla buttons in Grid” observation are version-specific to the tested WorldBox build.
Open the full TerraForge case study for the discovery sequence.