Plugin.ItemInserted Event

As a Roblox developer, it is currently impossible for plugins to detect when a developer inserts an item using the Insert Object menu.

The ability to detect when a developer inserts items would allow plugin creators to add global and context-specific defaults and behavior changes to objects. For example:

  • One could globally set all inserted parts to be anchored
  • One could insert a texture for every face when a Texture is inserted into a Part
  • One could add a default header to scripts that lists the time of creation and the creator
  • One could add a skybox search popup when inserting a skybox

While a single event would be great, a way to differentiate between the Insert Object menu, the Toolbox, Paste, and Paste Into would be awesome. Something that looks like…

Plugin.ItemInserted(Instance item, Enum.PluginInsertType insertType)

Enum.PluginInsertType
    InsertObject
    Toolbox
    Duplicate
    Paste
    PasteInto

If Roblox is able to address this issue, it would allow for expanded customization of Studio for developers.

10 Likes

How does http://wiki.roblox.com/index.php?title=API:Class/CollectionService/AddTag in conjunction with CollectionService events suffice for doing this?

Assuming you’re asking how it would work to get this functionality, it wouldn’t. To add the tag to added items, you would need to know which items were added via plugin. The feature you would need to do this anyway is the feature being requested here.


Really would love to have this. The way I like things to behave when inserted is often a lot different than how Roblox defaults it. This would save so much time.

I was reading it as the plugin creator having the ability to tag it such that a 3rd party could recognise it as inserted by that plugin rather than having the 3rd party recognise any part as created by a plugin in global.

I thought so too before reading this:

A plugin can detect when something is added by using the DescendantAdded event?

It does not suffice for doing this.

I need to detect when items are added using these menus:

Images



image
image

CollectionService will not work for any of these because...
  • Items inserted using these features do not have tags related to how they were inserted, so this is not something that can be done as a plugin developer right now.
  • Roblox can add tags related to how they were inserted, but…
    • Tags are supposed to be created by the developer and their personally chosen tools, not internally by Roblox for script events.
    • Using tags to categorize an item for only an instant goes against the fundamental nature of tags. Tags are supposed to stay attached to the object and be used to find it in the future. They are not supposed to be used once then disappear.
    • Using tags could lead to a script copying objects and them being incorrectly detected as user-inserts by plugins.
    • This would be like using CollectionService:GetInstanceAddedSignal(workspace)[1] to detect when a child is added to workspace. Roblox could totally set that up instead of ChildAdded, but it should be obvious that ChildAdded is the cleaner solution to the problem of detecting when a child is added. Similarly, Plugin.ItemInserted is the cleaner solution to the problem of detecting when the user inserts an item using Studio tools.

CollectionService does not even work as a workaround to this problem, so all we’re discussing is possible ways for Roblox to implement this for developers. A much cleaner and easier to use solution than CollectionService would be a new event.

[1]: I’m aware that only string tags can be used, but I needed to use an Instance as a tag to get across the example.


CollectionService works for this.


CollectionService does not work for this, but I don’t think you understand what this Feature Request is for.

This feature request is to detect when a developer/user uses the built in Studio tools to insert objects, such that plugins can customize what happens when users use the built in Insert Object menu, Toolbox panel, or other ways to insert objects. This feature has nothing to do with detecting when a plugin inserts objects. I think you’re misunderstanding because I’m stating that ItemInserted would be an event under the Plugin object.


DescendantAdded will fire when an item is created from anything, including any script, plugin, or Studio tool. I specifically want to detect when the user inserts an item manually using a built-in Studio tool, such as the Insert Object menu.

I am aware what the feature request is for, the second post was to clarify that I misread a particular usecase that indeed rules out CollectionService. Nonetheless, a check along with DescendantAdded for whether the insertion is done in run-time could eliminate all insertions but studio tools/plugins.

You are correct. It’s even possible to rule out most insertion by plugins by keeping a list of default object properties and only recognizing objects that are inserted with default properties.

It’s nice to have a workaround, but that’s a very messy solution that will not always work and that requires maintaining a list of the default properties (or otherwise hoping that Instance.new always has the same default properties as Studio).

I am not content with that messy, not-entirely-accurate solution. I do not want to detect plugin-created objects as user-created ever. I do not feel comfortable releasing any plugins that use an unreliable method to detect when the user creates an object.

game.DescendantAdded works fine for me

You can’t distinguish between whether you or someone else inserted the object with that (i.e. in Team Create), you can’t distinguish between an object being inserted and an object coming back into the hierarchy due to Undo, etc. It’s not the same.

6 Likes