Search Unity

[Resolved]Deep copy components

Discussion in 'Immediate Mode GUI (IMGUI)' started by TiagoMartins, Feb 5, 2016.

  1. TiagoMartins

    TiagoMartins

    Joined:
    Mar 15, 2015
    Posts:
    12
    Good morning

    I'm implementing a custom editor to create 2d terrains, and I would like to be able to duplicate them in the scene view,

    my problem is that at the moment I have components attaches to the terrain game object that contain object instances, like the following:
    TerrainComponent
    {
    NodePath path;
    ...
    }

    So when I duplicate my terrain object the path variable reference gets copied to the new terrain game object, and applying changes to it affects both the copied and the original terrain

    Is there a good way to have the path variable be deep copied to the new component, without trying to override the default duplicate event and copying all it's fields?
     
  2. TiagoMartins

    TiagoMartins

    Joined:
    Mar 15, 2015
    Posts:
    12
    After all everything with the data structure was fine, I had to override the duplicate event because the default one was creating a duplicate with the same mesh reference as the original terrain.