-1

As relatively new to Unity C#, i followed the guidance of this post: Build and load Assetbundles in Unity

I was able to successfully build the assetBundles into the StreamingMedia folder. But using this posts guidance on the second half of loading

The script will not compile with the error below. I am sure it is my relatively new skills in Unity, but i am wondering what i am missing. Once i can successfully recreate this, the eventual intent is to use it to load GameObject from the assetBundles.

Any guidance is most appreciated.

ERROR Referencing the "yield return asset;" line.

Error Assets/Scripts/loadBundleAsset.cs(22,23): error CS1519: Invalid token ';' in class, struct, or interface member declaration

appreciatively

Have attempted to follow the guidance of the previous post. Build and load Assetbundles in Unity Also have been doing reading about the use of EInumerators and Coroutine in Unity

Here is basis of the script as i interpreted that post.

IEnumerator LoadAsset(string assetBundleName, string objectNameToLoad)
{
    string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "AssetBundles");
    filePath = System.IO.Path.Combine(filePath, assetBundleName);

    //Load "animals" AssetBundle
    var assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(filePath);
    yield return assetBundleCreateRequest;

    AssetBundle asseBundle = assetBundleCreateRequest.assetBundle;

    //Load the "dog" Asset (Use Texture2D since it's a Texture. Use GameObject if prefab)
    AssetBundleRequest asset = asseBundle.LoadAssetAsync<Texture2D>(objectNameToLoad);
    yield return asset;

    //Retrieve the object (Use Texture2D since it's a Texture. Use GameObject if prefab)
    Texture2D loadedAsset = asset.asset as Texture2D;

    //Do something with the loaded loadedAsset  object (Load to RawImage for example) 
    image.texture = loadedAsset;
}

Script will not compile, indicating the following error. When placed in a full script i expected to compile.

Error Assets/Scripts/loadBundleAsset.cs(22,23): error CS1519: Invalid token ';' in class, struct, or interface member declaration

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
muckletone
  • 27
  • 1
  • 4

1 Answers1

2

I can see no error with this piece of code. Asuming I do not miss anything, that leaves one option: The compilers parsing is so messed up, the compiler can not even tell you where the error is anymore.

It thinks it is still in a preceeding "class, struct, or interface member declaration", propably because something messed up parsing the "end of that" brackets. Withou teh full code, it is hard to tell. And even with it, it can take a while to spot.

The only advise I can give is trying each part of the code out seperately. The one that throws a compiler error on it's own is definitely busted.

Christopher
  • 9,634
  • 2
  • 17
  • 31
  • Hello Christopher, thank you for the guidance, and will report what i discover from this incremental process. – muckletone Aug 05 '19 at 23:53
  • Hello again @Christopher thanks for the recommendation of this iterative approach. I was able as a result to have the script properly compile. The errant issues as the last line, image.texture = image. – muckletone Aug 06 '19 at 00:44
  • In that the RawImage declaration was unneeded, commenting those lines out solved the issue. Now, the real challenge is to implement and test this process of loading assets from an AssetBundle. Your response was very helpful, thanks – muckletone Aug 06 '19 at 00:48
  • @muckletone "The errant issues as the last line, image.texture = image." As with the Keys, it is always the last place you look at :) – Christopher Aug 06 '19 at 09:10