Hello! I’m having a problem trying to load an Streaming Asset on my Android game. It works neatly on the Editor, but not on the build. The error log is this one:
The code for loading the asset consists of two methods:
Everything that Praetor says above, plus this is my directory finder since Unity for some inscrutible bizarre reason thinks we want to care about these nitty gritty dirty laundry details of paths on different platforms:
using UnityEngine;
public static class StreamingAssetsPath
{
public static string StreamingAssetPathForWWW()
{
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
return "file://" + Application.dataPath + "/StreamingAssets/";
#endif
#if UNITY_ANDROID
return "jar:file://" + Application.dataPath + "!/assets/";
#endif
#if UNITY_IOS
return "file://" + Application.dataPath + "/Raw/";
#endif
throw new System.NotImplementedException( "Check the ifdefs above.");
}
public static string StreamingAssetPathForFileOpen()
{
#if !UNITY_EDITOR && UNITY_ANDROID
throw new System.NotImplementedException( "You cannot open files on Android. Must use WWW");
#endif
Debug.Log( "Application.streamingAssetsPath:" + Application.streamingAssetsPath);
return Application.streamingAssetsPath + "/";
}
}
hi, I want to load a unity.sentis ML model but getting this compilation error (Argument 1: cannot convert from ‘byte[ ]’ to ‘Unity.Sentis.ModelAsset’) while loading the download data.
void LoadModel()
{
//Load model
const string modelName = "yolov8n.sentis";
string modelPath = Path.Combine(Application.streamingAssetsPath, modelName);
var loadingRequest = UnityWebRequest.Get(modelPath);
loadingRequest.SendWebRequest();
while (!loadingRequest.isDone && loadingRequest.result == UnityWebRequest.Result.ConnectionError && loadingRequest.result == UnityWebRequest.Result.ProtocolError);
model = ModelLoader.Load(loadingRequest.downloadHandler.data);
}