Find unused events

Not sure if I missed there or not, is there a way to find which events in project are currently not being used? So, they are not linked via EventReference?

Hi,

Could I grab some more info? Is this just events that haven’t been played, or events that have not been assigned to an emitter or being referenced by an EventReference?

Thanks!

Hi,
sry for late reply (summer vacation)…

Yes, I’m simply looking for info, if an event is actually referenced. Goal is to to find unused events and then go bother audio artists to remove them (reduce build size).

I did a quick and (really) dirty hax on EventReferenceUpdater, which first collects all references and then checks it against current studio cache. It kinda works, but I broke a few things along the way, hence searching for a more proper solution :slight_smile:

Thanks for the info.

That is not a feature we currently have but I will pass it onto our development team to investigate further.

If you could share you updated EventReferenceUpdater.cs and the issues it is having we could try fix that in the mean time?

I’ve added another func

        private void BeginSearchingForUnused()
        {
            var eventCacheGuids = AssetDatabase.FindAssets("t:EventCache");
            if (eventCacheGuids.Length == 0)
            {
                return;
            }

            var referencedGuids = new HashSet<Guid>();
            foreach (var task in tasks)
            {
                var g = new Guid(task.DataPublic[task.DataPublic.Length - 1]);
                referencedGuids.Add(g);
            }

            var eventCache = AssetDatabase.LoadAssetAtPath<EventCache>(AssetDatabase.GUIDToAssetPath(eventCacheGuids[0]));
            for (var index = 0; index < eventCache.EditorEvents.Count; index++)
            {
                var editorEvent = eventCache.EditorEvents[index];
                EditorUtility.DisplayProgressBar($"Searching {index} of {eventCache.EditorEvents.Count - 1}", editorEvent.Path, (float)index / eventCache.EditorEvents.Count - 1);

                if (referencedGuids.Contains(editorEvent.Guid))
                {
                    continue;
                }

                Debug.LogError($"FMOD Event is not referenced: {editorEvent.Path}");
            }

            EditorUtility.ClearProgressBar();
            StopProcessing(true);
        }

But I 've had some issues when logic was parsing serialized data, had to add this to handle some arrays/lists I think…

private static IEnumerable<Task> GetGenericUpdateTasks(object target, string subObjectPath = null, IEnumerable<object> parents = null)
        {
            Type targetType = target.GetType();

            if (targetType == typeof(EventReference))
            {
                EventReference eventReference = (EventReference)target;
                Task updateTask = GetUpdateEventReferenceTask(eventReference, subObjectPath, subObjectPath);
                if (updateTask != null)
                {
                    yield return updateTask;
                }
            }

            FieldInfo[] fields = targetType.GetFields(DefaultBindingFlags);

And a few try/catch handlers along the way :slight_smile:

I then “broke” this:

private static Task GetUpdateEventReferenceTask(EventReference eventReference, string fieldName,
            string subObjectPath = null)
        {
            if (eventReference.IsNull)
            {
                return null;
            }

            if (Settings.Instance.EventLinkage == EventLinkage.GUID)
            {
                EditorEventRef editorEventRef = EventManager.EventFromGUID(eventReference.Guid);

                if (editorEventRef == null)
                {
                    return null;
                }

                // !!!! force true to enumerate everything...
                if (eventReference.Path != editorEventRef.Path || true)
                {
                    return Task.UpdateEventReferencePath(subObjectPath, fieldName, eventReference.Path,
                        editorEventRef.Path, eventReference.Guid);
                }
            }

In the end I ran the update task first, which just collected everything, and then run my custom task to check against the cache…

Like I said, kinda works, but ugly…

1 Like

Thank you for the code snippets, I’m having some issues integrating that into my own script. Would it be possible to get the full script uploaded to your profile for me to test?

it’s up

1 Like

Hi, apologies for the delayed response.

I have added your script to the task but I haven’t ironed the issues yet. I will update you as soon as I can.