Load Asset At Path PROBLEM!

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.

[…]

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

LoadAssetAtPath is for use in the editor. It’s not for use in built apps. I think you’re looking for Resources.Load instead.

Cheers,

  • Joe
1 Like

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.

Hello,

Please follow the link given below .And do let me know if you have any concern.

Thanks
Seasia

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 :slight_smile:

1 Like