Skip to content

Added GM:OnDuplicated(ent, entDupeTable)#2408

Open
Grocel wants to merge 1 commit intoFacepunch:masterfrom
Grocel:minor-duplication-hook-addition
Open

Added GM:OnDuplicated(ent, entDupeTable)#2408
Grocel wants to merge 1 commit intoFacepunch:masterfrom
Grocel:minor-duplication-hook-addition

Conversation

@Grocel
Copy link
Contributor

@Grocel Grocel commented Dec 13, 2025

Works like ENTITY:OnDuplicated(ent, entDupeTable) but doesn't require adding/detouring ent.OnDuplicated on OnEntityCreated calls for addon-foreign entities.

This adds a easy way to add generic logic early to the duplication life cycle. It is called a way before duplicator.RegisterEntityModifier() added callers are being iterated. The new hook also reduces the risk of conflicts caused by detours of pre-existing ent.OnDuplicated code.

Test script:

if SERVER then
    hook.Add("OnDuplicated", "Test", function(ent, entTable)
        print(ent)
        PrintTable(entTable)
    end)
end

Works like `ENTITY:OnDuplicated(ent, entDupeTable)` but doesn't require adding/detouring `ent.OnDuplicated` on `OnEntityCreated` calls for addon-foreign entities.
Grocel added a commit to Grocel/advdupe2 that referenced this pull request Dec 13, 2025
In adjacent to: Facepunch/garrysmod#2408

Works like `ENTITY:OnDuplicated(ent, entDupeTable)` but doesn't require adding/detouring `ent.OnDuplicated` on `OnEntityCreated` calls for addon-foreign entities.
Grocel added a commit to Grocel/sligwolf_addon_base that referenced this pull request Dec 14, 2025
Removes the need for the "OnEntityCreated" hack.

Requires these pull request to be merged:
- Facepunch/garrysmod#2408
- wiremod/advdupe2#528
@marchc1
Copy link

marchc1 commented Dec 14, 2025

Would be very useful to have this hook coming from the perspective of a developer on ACF-3. We've wanted something like this for a while, iirc

@thegrb93
Copy link
Contributor

thegrb93 commented Dec 14, 2025

The name should be something more like PostDuplicatorPaste which is more consistent with the PostEntityPaste hook.

@Grocel
Copy link
Contributor Author

Grocel commented Dec 14, 2025

The name should be something more like PostDuplicatorPaste which is more consistent with the PostEntityPaste hook.

Don't think it would reflect what it does. It is called in the beginning if the duplication process (even before ent:Spawn()), not the end of it. The name is being picked as an analog to of the entity's hook name.

However what do you think of naming it OnEntityDuplicated instead?

@thegrb93
Copy link
Contributor

thegrb93 commented Dec 14, 2025

Oh I thought you were adding a post paste hook, which gmod also needs. Nvm

@Grocel
Copy link
Contributor Author

Grocel commented Dec 14, 2025

Oh I thought you were adding a post paste hook, which gmod also needs. Nvm

If this one gets of the ground, I can submit PRs adding those for both projects as well.

@robotboy655
Copy link
Collaborator

robotboy655 commented Dec 15, 2025

My concern with this is cost of execution. This is already a problem for large dupes.

A post-duplication hook would be a safer bet, even if it would be more annoying to work with to modify a single entity entry.

@Grocel
Copy link
Contributor Author

Grocel commented Dec 15, 2025

My concern with this is cost of execution. This is already a problem for large dupes.

A post-duplication hook would be a safer bet, even if it would be more annoying to work with to modify a single entity entry.

  1. It should be O(n) for entity count of dupe, or O(1) for a single entity. Similar how ent.OnDuplicated() already is.
  2. Adding a post hook after dupe would not do this justice as it is specifically asked to have a hook that runs early on the pipeline and per entity.
  3. A hook running in post is something I would like to make in an separate PR.

Can we ensure that there is no misunderstanding between your and my idea?

@robotboy655 robotboy655 added the Addition The pull request adds new functionality. label Dec 16, 2025
@marchc1
Copy link

marchc1 commented Dec 18, 2025

My concern with this is cost of execution. This is already a problem for large dupes.

A post-duplication hook would be a safer bet, even if it would be more annoying to work with to modify a single entity entry.

I think it would be worth actually profiling the cost vs a hypothetical before coming to this conclusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Addition The pull request adds new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants