Sprite disappears after spawned

im trying to make a sprite spawn via instantiate. when it spawns it performs an animation that i have set to it but is invisible. order in layer is fine, z position is fine (its in 2d) and if i drag the prefab straight from the project menu theres no problems, only when instantiating it. any help?

void SpawnAttack (string dir, int speed, string color)
    {
        GameObject atk = Instantiate(Attack, attackSpawn.position, attackSpawn.rotation);
        atk.transform.SetParent(UiMaster);
        if (dir == "left")
        {
            atk.SendMessage("BeLeft");
        }
        if (dir == "right")
        {
            atk.SendMessage("BeRight");
        }
        if (dir == "up")
        {
            atk.SendMessage("BeUp");
        }
        if (dir == "down")
        {
            atk.SendMessage("BeDown");
        }
        if (color == "red")
        {
            atk.GetComponent<SpriteRenderer>().color = Red;
        }
    }

I suspect the problem is with the animator. When you run the animation once and after that nothing it has nothing to render try adding a looping animation (can be a still image) after the effect.

Some other possibilities:
you might want to double

  • check the rotation. If it’s
    accidentally standing perpendicular
    out of screen layer, you can’t see it
    (ortho cam specific).
  • check the position: double click the
    gameObject in the inspector, and it
    get’s centered in the scene view.
    regards
    Ejoo