Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question AssetBundle.LoadFromFile not defined?!

Discussion in 'Asset Bundles' started by WilB, Aug 21, 2023.

  1. WilB

    WilB

    Joined:
    Oct 25, 2012
    Posts:
    17
    I've been using Unity for over 10 years and this has me stumped! So I'm doing / missing something stupid.

    I'm attempting to load an AssetBundle (Unity version 2022.1, Windows 10 Pro). It's as simple as this:

    Code (CSharp):
    1. using System;
    2. using System.IO;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. private const string TestAssetPackageName = "TestPackage";
    7. .
    8. .
    9. var bundle = AssetBundle.LoadFromFile (Path.Combine (Application.streamingAssetsPath, TestAssetPackageName));
    And what I get when compiling it is a bizarre error: 'AssetBundle' does not contain a definition for 'LoadFromFile'.
     
  2. WilB

    WilB

    Joined:
    Oct 25, 2012
    Posts:
    17
    Further info: by starting a fresh new Unity project and attempting to access the same asset bundle via AssetBundle.LoadFromFile, everything was fine. In other words, it seems that my [LARGE] Unity project has been corrupted and I will have to find a way to rebuild it.
     
  3. WilB

    WilB

    Joined:
    Oct 25, 2012
    Posts:
    17
    [RESOLVED]
    Pay attention to namespaces and class names! This was an embarrasing "gotcha" on my part. In a long-forgotten test a few years ago, an intern created a class named "AssetBundle" within the project. Needless to say, this class collided with the UnityEngine.AssetBundle class. As soon as the project AssetBundle class was removed from the project (and unused anyway), all issues of course disappeared.
     
    AndrewSkow likes this.