Add Copy, Paste As New, and Paste values for Components - #316
Conversation
|
If im not mistaken, Echo has a DeserializeInto, so instead of manually doing everything, in theory you can simply do Serializer.Serialize(Component) and Serializer.DeserializeInto(Component) to copy all serializable fields over and also trigger Serialization Callbacks. That should be able to simplify a lot of this down a ton! Could you look into that? |
|
That does make things easier, and also helps to hit a potential bug like with audio source where the fields are all private but are deserialized in its own Deserialize method. Also lets me drop the hashset and manually looping, and a few null guards since they're no longer possible to hit. Also cleaned up a few comments (and noted that audio source thing for future reference) |
|
Hmm though it seems your still doing additional work to work around a limitation in Echo? Give me a bit to see if I can come up with a nice solution inside Echo (Some kind of Reference Resolver) |
|
Right, currently (from my understanding at least) Echo clones out-of-graph references by value, so I believe the only way to shrink it would be by having some kind of "identifier-aware reference" in Echo so that we don't have to effectively replicate that here. Granted my experience with serialization is largely just custom unity editor's, so the guts of it I'm not 100% on (I could be making false assumptions fwiw) But that said, I think that if Echo were to have that, then that also allows for that limitation above to potentially be resolved "for free" with getting to hit fields beyond the top level. |
|
Thats pretty much my plan, Im gonna add something like: public interface IExternalReferenceResolver That you can implement, to let you reference out-of-graph things rather then cloning them. |
|
Alright, just pushed it all and nuget is live so the main branch of the editor has the new version of Echo. Also Heres what I added: /// <summary>
/// Lets a caller mark object references that live outside the graph being serialized so Echo links
/// to them by a stable key instead of inlining (and, on deserialize, deep-copying) them.
/// The classic case is copy/paste of a scene object: references to other objects in the selection
/// should be duplicated, but references pointing out of the selection should resolve back to the
/// original live instances rather than spawning copies.
/// Set one on <see cref="SerializationContext.ExternalReferences"/>.
/// </summary>
public interface IExternalReferenceResolver
{
/// <summary>
/// Called during serialization for every reference-type value. Return a stable key when
/// <paramref name="value"/> is external and should be linked rather than serialized; return null
/// to serialize it normally. Keys should be simple, self-contained values (a Guid, string, int,
/// or small struct) so they round-trip on their own.
/// </summary>
object? GetReferenceKey(object value);
/// <summary>
/// Called during deserialization to turn a key produced by <see cref="GetReferenceKey"/> back into
/// the live instance. <paramref name="targetType"/> is the reference's declared/serialized type.
/// Return null if the reference can no longer be resolved.
/// </summary>
object? ResolveReference(object key, Type targetType);
}Inside SerializationContext.cs as a new field you can pass in: public IExternalReferenceResolver? ExternalReferences;That should be able to fix the out-of-graph cloning and allow you to significantly simplify the code! |
|
Ah sorry, I made a mistake I'll have it fixed and in main branch on prowl in a moment |
|
No worries, I'm in no rush! |
|
Alright should all be live now on main branch! sorry about that. |
commit 654aaf6 Merge: 1834a31 6ba843b Author: Wulferis <acer1171090@gmail.com> Date: Sat Jul 25 02:32:36 2026 +1000 Merge branch 'main' of https://github.com/ProwlEngine/Prowl commit 1834a31 Author: Wulferis <acer1171090@gmail.com> Date: Sat Jul 25 02:32:32 2026 +1000 Updated prowl packages to v2.8.5 commit 6ba843b Merge: 06e9525 07f61cf Author: Wulferis <acer1171090@gmail.com> Date: Sat Jul 25 01:14:14 2026 +1000 Merge pull request ProwlEngine#322 from Acissathar/fix-show-in-explorer-relative-path-mismatching-slashes Normalize separators in Show in Explorer commit 07f61cf Author: Will B <willbentz92@outlook.com> Date: Fri Jul 24 09:02:15 2026 -0600 Normalize separators in Show in Explorer commit 06e9525 Merge: 7cbdf72 17e7597 Author: Wulferis <acer1171090@gmail.com> Date: Fri Jul 24 19:39:47 2026 +1000 Merge pull request ProwlEngine#318 from Acissathar/fix-collider-gizmo-offset-incorrect-rotation Fix collider DrawGizmo incorrecly placed the shape's Center offset through the combined rotation, leading to mismatch between actual physics shape and debugging commit 7cbdf72 Merge: a5b09e4 ab9073a Author: Wulferis <acer1171090@gmail.com> Date: Fri Jul 24 15:16:39 2026 +1000 Merge pull request ProwlEngine#314 from PaperPrototype/empty-vertices-mesh-data Add error message for "Vertices data must not be empty when assigning vertex data" commit a5b09e4 Merge: d0ea15b 6794e5b Author: Kai Angulo <116330012+sinnwrig@users.noreply.github.com> Date: Thu Jul 23 21:30:00 2026 -0700 Merge pull request ProwlEngine#317 from PaperPrototype/fix-release-runner Update launch.json commit d0ea15b Author: Wulferis <acer1171090@gmail.com> Date: Fri Jul 24 14:10:22 2026 +1000 Updated prowl packages to v2.8.2 commit 3fb5f74 Author: Wulferis <acer1171090@gmail.com> Date: Fri Jul 24 13:31:57 2026 +1000 More robust type resolving and scene deserialization commit b96156c Author: Wulferis <acer1171090@gmail.com> Date: Fri Jul 24 13:31:24 2026 +1000 Updated all prowl packages to v2.8.1 commit 17e7597 Author: Will B <willbentz92@outlook.com> Date: Thu Jul 23 15:32:30 2026 -0600 Fix collider DrawGizmo incorrecly placed the shape's Center offset through the combined rotation, leading to mismatch between actual physics shape and debugging commit 6794e5b Author: Abdiel Lopez <48071553+PaperPrototype@users.noreply.github.com> Date: Thu Jul 23 16:46:03 2026 -0400 Update launch.json commit ab9073a Author: Abdiel Lopez <48071553+PaperPrototype@users.noreply.github.com> Date: Thu Jul 23 02:48:10 2026 -0400 Update Mesh.cs
|
This does help shrink it down, but we may be able to shrink it a little more. A couple of notes before I push up any changes to hear your thoughts on:
As is though, we're cutting approx 100 lines (granted a chunk is comments), but it is leaner! |
|
|
Totally understandable, that's why I wanted to check first so no worries. I will give it a spin and see about putting them in Editor, thanks! |
|
Moved the scene reference resolver to its own class in the Editor Core, which let us chop out even more lines. I didn't include moving over the GameObject/Prefab duplication to this yet, I figured that might be better as its own PR for clarity? I don't mind including it though if you'd prefer it just be as one batch. |
|
I think this will become even smaller soon! The Undo code you have is accounting for assembly unloading. We'll hold onto this PR for when Hotreload is merged in, This PR so far is good as is, if some wants to use it I think its pretty much perfect for main branch as is. I just dont want to merge just yet because of the change to Assembly Loading incoming. |
|
Sounds good to me! |
Summary
This adds a component clipboard option in the component menu of the editor for Copy Component, Paste Component As New, and Paste Component Values inspired by other engines. The payload goes on the system clipboard as text so it can survive scene swaps and can copy from inside Prefab Edit mode to then exit and paste onto a scene object.
Example
Notes
Limitations