Home > front end >  Problem with Asset Bundles in Unity 2020.3.30f1
Problem with Asset Bundles in Unity 2020.3.30f1

Time:03-11

i've a problem with my object contained in the Bundle because it is instancied without textures (materials). Now i will explain you what i've do. I've installed AssetBundles Browser package into unity for make me easier the creation of AssetBundles. I've created a prefab called "Cheese2" with some components attached

This is the inspector of the object

And i've created a new AssetBundle called "test2"

After this i've looked at the AssetBundle Browser and i've saw that the AssetBundle has been configured corretly with all his dependencies (AssetBundles Browser include automatically all the dependencies of the object)

This is the AssetBundles Browser windows with my Bundle "test2" and all the Assets

Ok, after this i've build the bundle into my folder "StreamingAssets" and has been created some files

Now it's time to see the script:

public void Evoca()
    {

    var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "test2"));
    
    if (myLoadedAssetBundle == null)
    {
        Debug.Log("Failed to load AssetBundle!");
        return;
    }
    
    var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("Cheese2.prefab");
    Instantiate(prefab, transform.position   (transform.forward * 1), Quaternion.identity);

}

How you can see i've created a variable called "myLoadedAssetBundle" for select the Bundle and a variable called "prefab" for select what asset of the bundle i've to instance (in this case is Cheese2.prefab) and, after this, i've instanciated the asset Cheese2.prefab.

I call the function "Evoca" (the function for instantiate the AssetBundle) with the pressure of a button but the result is this.

How can you see my Cheese is without textures and i don't undestand why. The "scripts" and the "box collider" attached to my component works properly.

I've just tried to create another AssetBundle called "dependencies" with all the dependencies of my object and precharge it before the load of "test2" (accordly to the unity manual)

Something like this:

    public void Evoca()
{
    var dependencies= AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "dependencies"));
    
    var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "test2"));
    
    Debug.Log(dependencies);
    if (dependencies== null)
    {
        Debug.Log("There is a problem with your dependencies!");
        return;
    }
    if (myLoadedAssetBundle == null)
    {
        Debug.Log("Failed to load AssetBundle!");
        return;
    }
    
    var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("Cheese2.prefab");
    Instantiate(prefab, transform.position   (transform.forward * 1), Quaternion.identity);
    
}

But it doesn't work.

Can someone help me?

CodePudding user response:

i've found the solution. The problem is of the unity "game" simulator, i've see this post on reddit and i've thought "wait, if i try the application on my phone, does it work correctly?". The Answer is YES, on my Phone it works correctly and all the textures are charged with the asset.

  • Related