public EntityViewModel Duplicate() { var flags = SubHierarchyCloneFlags.GenerateNewIdsForIdentifiableObjects; var clonedHierarchy = EntityHierarchyPropertyGraph.CloneSubHierarchies(Asset.Session.AssetNodeContainer, Asset.Asset, AssetSideEntity.Id.Yield(), flags, out Dictionary <Guid, Guid> idRemapping); AssetPartsAnalysis.GenerateNewBaseInstanceIds(clonedHierarchy); var addedRoot = clonedHierarchy.Parts[clonedHierarchy.RootParts.Single().Id]; addedRoot.Folder = (Parent as EntityFolderViewModel)?.Path; // rename the entity to avoid having the same names if (Parent == null) { throw new InvalidOperationException($"{nameof(Parent)} cannot be null"); } addedRoot.Entity.Name = EntityFactory.ComputeNewName(Parent, addedRoot.Entity.Name); Asset.AssetHierarchyPropertyGraph.AddPartToAsset(clonedHierarchy.Parts, addedRoot, (Parent.Owner as EntityViewModel)?.AssetSideEntity, Parent.Owner.IndexOfEntity(this) + 1); var cloneId = addedRoot.Entity.Id; // The view model should already exist at that point var partId = new AbsoluteId(Asset.Id, cloneId); var viewModel = (EntityViewModel)Editor.FindPartViewModel(partId); // TODO: Offset a bit (by 1 scene unit horizontally?) the cloned entity so it appears distincly from the source entity return(viewModel); }