Reference Sound Event by GUID

How can I reference a Soundevent in a script by GUID?
in Unity scripts I usually create a public string, so I can use the [FMODUnity.EventRef] attribute to browse for events in the gameobject inspector.
Is it possible to keep the browse feature but storing a GUID reference to SoundEvent instead ?

Yes, you can reference events by their GUID. You can use the public string for the path and pass that into the PathToGUID function to get the GUID of that event.

Thanks Richard but this won’t solve the problem of storing the string into the inspector.
I’d like to avoid the use of string references stored in unity pub var, so I can rename events and they still works. I’m searching for a solution that allow me to browse for the event with the browser but stores the GUID (not the string) into the Unity public variable. I’ve read that FMOD 2 allow a direct GUID reference, but what about the inspector? Is that possible?
I think a specific attribute for GUID type var could solve the problem in an elegant way


Gianni Ricciardi

CEO & Music Producer

You can do something like this:

[FMODUnity.EventRef] [SerializeField]
private string fmodEvent;

public System.Guid FmodEvent
    get { return FMODUnity.RuntimeManager.PathToGUID(this.fmodEvent); }

you are still able to select the event in the inspector and then you can use the FmodEvent property to do stuff with the event GUID. You will need to create a property for each event though.

1 Like