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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Problems loading assetbundle

Discussion in 'Scripting' started by vegagro, Apr 14, 2023.

  1. vegagro

    vegagro

    Joined:
    Mar 20, 2021
    Posts:
    2
    So I have created an assetbundle with three gameobjects just as a test. In the manifest file alle the gameobjects are in the Assets:

    (From the text file)
    Assets:
    - Assets/Potet.prefab
    - Assets/PlayerCharacter/Prefabs/Female.prefab
    - Assets/PlayerCharacter/Prefabs/Male.prefab

    However, when I try loading all the assets, only the Female.prefab loads. I'v tried to spesifically load the Male and Potet, which does not give any errors in the console, it just simply does not load or Instantiates in the scene.

    This is my script:

    AssetBundle assetBundle
    = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "AssetBundles", "characters"));

    if (assetBundle == null)
    {
    Debug.Log("Failed to load AssetBundle!");
    return;
    }

    GameObject[] characters = assetBundle.LoadAllAssets<GameObject>();
    foreach(GameObject character in characters)
    {
    Debug.Log(character);
    }

    And this only logs the female:

    Female (UnityEngine.GameObject)
    UnityEngine.Debug:Log (object)
    LoadCharacterFromFile:Start () (at Assets/CharacterCreation/Scripts/LoadCharacterFromFile.cs:23)

    Does anyone know what could cause this problem?
     
  2. vegagro

    vegagro

    Joined:
    Mar 20, 2021
    Posts:
    2
    I was too hasty in posting my problem here! I had an error in my editor script while creating the asset bundles, which resulted in having two files of the same type. Consequently, I was loading the wrong file.