# Add Event in Unity Editor not work!

**URL:** https://qa.fmod.com/t/add-event-in-unity-editor-not-work/22191
**Category:** Unity
**Tags:** unity
**Created:** [October 17, 2024, 9:29am UTC](https://qa.fmod.com/t/add-event-in-unity-editor-not-work/22191 "2024-10-17T09:29:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pantherastudio](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@pantherastudio](https://qa.fmod.com/u/pantherastudio)
#### Post date: [October 17, 2024, 9:29am UTC](https://qa.fmod.com/t/add-event-in-unity-editor-not-work/22191/1 "2024-10-17T09:29:04Z")

</div>

Hello, i can’t create new Event FMOD from Unity because i have many banks, so it meet error when BuildTree function in CreateEventPopup.cs

```private
{
var rootGuid = EditorUtils.GetScriptOutput("studio.project.workspace.masterEventFolder.id");
rootFolder = new FolderEntry();
rootFolder.guid = rootGuid;
BuildTreeItem(rootFolder);
wantsMouseMove = true;
banks = new List();
        const string buildBankTreeFunc =
            @"function() {
                var output = """";
                const items = [studio.project.workspace.masterBankFolder];
                while (items.length > 0) {
                    var currentItem = items.shift();
                    if (currentItem.isOfType(""BankFolder"")) {
                        currentItem.items.reverse().forEach(function(val) {
                            items.unshift(val);
                        });
                    } else {
                        output += "","" + currentItem.id + currentItem.getPath().replace(""bank:/"", """");
                    }
                }
                return output;
            }";

        string bankList = EditorUtils.GetScriptOutput(string.Format("({0})()", buildBankTreeFunc));
        string[] bankListSplit = bankList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (var bank in bankListSplit)
        {
            var entry = new BankEntry();
            entry.guid = bank.Substring(0, 38);
            entry.name = bank.Substring(38);
            banks.Add(entry);
        }
    }`

```

when i increaseto bigger 2048 bytes in this function at EditorUtils, it works…

```auto
public static string GetScriptOutput(string command)
        {
            byte[] commandBytes = Encoding.UTF8.GetBytes(command);
            try
            {
                ScriptStream.Write(commandBytes, 0, commandBytes.Length);
                byte[] commandReturnBytes = new byte[2048];
                int read = ScriptStream.Read(commandReturnBytes, 0, commandReturnBytes.Length);
                string result = Encoding.UTF8.GetString(commandReturnBytes, 0, read - 1);
                if (result.StartsWith("out():"))
                {
                    return result.Substring(6).Trim();
                }
                return null;
            }
            catch (Exception)
            {
                networkStream.Close();
                networkStream = null;
                return null;
            }
        }

```

What should i do? many thanks!!

---

<div class="post-metadata">

### Author: ![pantherastudio](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@pantherastudio](https://qa.fmod.com/u/pantherastudio)
#### Post date: [October 24, 2024, 3:11am UTC](https://qa.fmod.com/t/add-event-in-unity-editor-not-work/22191/2 "2024-10-24T03:11:57Z")

</div>

@Connor_FMOD can you help me please ☹

---

<div class="post-metadata">

### Author: ![pantherastudio](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@pantherastudio](https://qa.fmod.com/u/pantherastudio)
#### Post date: [October 24, 2024, 3:15am UTC](https://qa.fmod.com/t/add-event-in-unity-editor-not-work/22191/3 "2024-10-24T03:15:46Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/b/bf80ab6d36d29060a85b79465851fd6028d02903.png)

i meet error when add event in unity, but if i change function like this in EditorUtils.cs, it fixed

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/f/fbd38a5c017755d63af51e20918b44e186d90879.jpeg)

---

<div class="post-metadata">

### Author: ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)
#### Post date: [October 25, 2024, 12:49am UTC](https://qa.fmod.com/t/add-event-in-unity-editor-not-work/22191/4 "2024-10-25T00:49:16Z")

</div>

Thanks for reporting this, it does look like it’s possible to get an `ArgumentOutOfRangeException` as the Bank tree is built, if the entire list of bank strings is greater than the byte array in `GetScriptOutput`.

I have raised a task to investigate a solution for it but for now this is something that will need to be handled like you have shown.

---

<div class="post-metadata">

### Author: ![pantherastudio](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@pantherastudio](https://qa.fmod.com/u/pantherastudio)
#### Post date: [October 28, 2024, 5:00am UTC](https://qa.fmod.com/t/add-event-in-unity-editor-not-work/22191/5 "2024-10-28T05:00:15Z")

</div>

okay, thank you for reply
