Search Issue Tracker

Won't Fix



Found in






Issue ID




MenuItem is executed more than once when multiple objects are selected



How to reproduce:
1. Open attached project
2. Open SampleScene
3. In Hierarchy view, make none of object is selected and run "My Test Menu" in right-click context menu. You can see single "0" is displayed in Console.
4. Select both "Main Camera" and "Directional Light" in Hierarchy view, and run "My Test Menu" again. You can see two "2" are displayed. It should be called once.

Reproducible with: 2017.4.23f1, 2018.3.9f1, 2019.1.0b7, 2019.2.0a8

Actual results: MenuItem Script gets executed twice when multiple objects are selected and it's called from the Hierarchy
Expected results: It should only be called once when multiple objects are selected

Notes: the issue does not reproduce if you call this script via GameObject>My Test Menu

  1. Resolution Note (2019.2.X):

    We really appreciate your contribution to the Unity product. Thank you for reporting this issue. We take every case submitted to us seriously by investigating the impact on you, our customer, as well as the impact it may have on the engineering and experience of our product.

    This particular case has been investigated thoroughly and we have decided, in the interests of protecting the stability and features of Unity for users that rely upon the affected versions, to not address this issue. This behavior applies to all items that are selected for all the MenuItems in that specific menu, and you can verify this yourself by selecting multiple objects and create a new object or camera. It will be added to all of the selected items.

Comments (10)

  1. MUGIK

    Jun 13, 2023 23:12

    Lol, it's ridiculous.
    In GameObject menus it executes once, in the hierarchy's context menu it executes for each selected game object. And there is no way to know how this command is called. BRILLIANT.

    But what if I'm doing objects grouping? Yeah, I'm getting very interesting objects tree
    --------finally grouped children

    And still, this behavior is not specified in the documentation.
    What a mess...

  2. unity_9F3218D57095C74D39E8

    Jan 31, 2023 17:04

    private static int gameObjectsCounter;

    private static void ProcessGameObject()
    if (gameObjectsCounter < Selection.gameObjects.Length) {

    gameObjectsCounter = 0;

  3. boyin

    Sep 10, 2022 09:23

    It's easy to fix, so why not?

  4. snarlynarwhal

    Jul 22, 2022 19:20

    Can this bug be resolved in a way that retains backwards compatibility? For example, additional MenuItem parameters or a new attribute altogether? At the very least, this behavior needs to be documented in

  5. SLGSimon

    Mar 29, 2022 21:32

    Had this in 2020.3.31, was wondering why my menu item was getting called continuously. Is there any way to check if this is happening? Seems pretty ridiculous that this is left in for backwards compatibility.

  6. BradZoob

    Nov 23, 2019 04:26

    wow, thought i was losing my mind, documentation mentions this nowhere, I searched high and low for some reason why i just created hundreds of prefabs from a context menu, and ok so a misfiring bubble event is now a feature, well okey dokey then.... Please document it, the potential runaway madness in editorscripts is scary.

  7. eddieray7

    Jun 03, 2019 14:52

    As far as "backwards compatibility" goes, if you successfully avoid the N times N calls to your script, the script will also work if it's called just once like it should be. And more importantly, the same script MUST ALREADY WORK when it gets called once for 20 selected objects (because that's how it works in the GameObject menu - which doesn't exhibit the bugged behavior) as it does when it gets called N times with N selected objects.

    Clarification: The script gets called 20 times on 20 objects... not 400 times... but the result is that unless you code around this you will end up processing "400 objects" instead of 20.

  8. eddieray7

    Jun 03, 2019 14:44

    This same behavior occurs in Unity 5.6.7f1. The only way to deal with this issue is to code the MenuItem script such that it can detect if it already processed an object before. Calling the MenuItem script 400 times when there is a selection of 20 objects is just broken.

  9. datagreed

    May 30, 2019 17:26

    Oh, I didn't see the grey text. I get the backwards-compatability issue, but what are you supposed to do when you need to do something with all selected items only once?..

  10. datagreed

    May 30, 2019 17:25

    So, why is this won't fix? How are we supposed to handle different behaviour when selecting something from the Project Hierarchy pane or from main Unity menu?..

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.