TLDR; Is there a way to fill in a string parameter in the Inspector by dragging a Streaming Asset file?
Explanation:
I use Streaming Assets to load a lot of files… It would be really helpful to be able to drag a file from the Streaming Assets folder to a string parameter on a script in the Inspector and get the full file path in the string parameter.
It seems like I would need a Custom Editor script to do this and then use the DragAndDrop API to get the file paths, but it is empty. It looks like dragging a Streaming Asset is not allowed and is ignored by the DragAndDrop API.
Since you can use Application.streamingAssetsPath as a shortcut, the only other thing needed is file name and subfolders, which you could just fill in yourself. Why do you need to drag and drop?
Imagine typing the names in for 100 files… I don’t want to type the file names and subfolders for all those files. Drag and drop would be much easier and mirrors how actual assets are assigned.
I have used the above technique of using only UnityEngine.Object. But this fails for me in WebGL builds in Unity 2022.2.15 because myStreamingAssetFile is simply null. And that’s why myStreamingAssetFile.name throws an exception. I have no idea what is going on there.
It’s been years since I have looked at this code (and missed your reply!), but I think you are right. Thanks for pointing that out!
The [SerializeField] private Object streamingAsset; should be surrounded with a #if UNITY_EDITOR guard so it is excluded from compilation. Only the string path to the asset is intended to be serialized onto the GameObject and compiled into the build.