Search Unity

Load Asset At Path PROBLEM!

Discussion in 'Scripting' started by Simonxzx, Apr 26, 2015.

  1. Simonxzx

    Simonxzx

    Joined:
    Feb 22, 2015
    Posts:
    129
    Hi everyone, i'm trying to load some assets in a specific moment in my game wit a script (below). When I start the game everyting's ok, but when I try to build it Unity returns me this error : 'unityengine.resources does not contain a definition for LoadAssetAtPath' and below : 'Error building Player because scripts had compiler error'.
    Have you any idea ? Thank you very much.

    [...]
    Code (CSharp):
    1. if (prob_bonus_exit[(multiplier - 1), randm_bonus] == 1) // se è un bonus
    2.                     {
    3.                         int rand_val_bonus = Random.Range(0, 24);
    4.                         GameObject clone = Instantiate(BonusSphere, new Vector3(positions[randomrr], heights[(multiplier - 1), randomh], -1), Quaternion.identity) as GameObject;
    5.                         clone.transform.SetParent(gameObject.transform);
    6.                         clone.GetComponent<Rigidbody2D>().gravityScale = 0.7f * Force;
    7.                         clone.name = "b_bonus_" + probability_bonus[rand_val_bonus];
    8.                         clone.GetComponent<SpriteRenderer>().sprite = (Sprite)Resources.LoadAssetAtPath("Assets/Imgs/MainScene/Meteorites/FallingSphere" + probability_bonus[rand_val_bonus] + ".png", typeof(Sprite));
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Kiwasi likes this.
  3. soranthalas

    soranthalas

    Joined:
    Feb 1, 2014
    Posts:
    3
    This was working in the editor's Play mode until today. See the documentation change for LoadAssetsAtPahth? "Removed in version 5.0.1p2" So it sounds like there was some kind of breaking change. But I'm on 1f1, not 1p2.
     
  4. SeasiaInfotechind

    SeasiaInfotechind

    Joined:
    Nov 17, 2014
    Posts:
    32
  5. Simonxzx

    Simonxzx

    Joined:
    Feb 22, 2015
    Posts:
    129
    I've solved the problem by using Resources.Load guys !
    Seasia, i've followed your link but in my case it was good the first solution I've told before. Anyway, thank you very much :)
     
    JoeStrout likes this.