0

I have a particle system BloodSpill that is Instantiated when the player dies by:

Instantiate(bloodSpillEffect, transform.position, transform.rotation);

However, it will appear behind all other sprites (background, ground etc.) NO MATTER what I do. I have the particle system as a prefab and it's sorting layer is set as the same as the player's both programatically and through the options. It's position on the Z axis is also closer to the camera than other objects.

Actually, if I drag one from the prefabs folder and put it in the scene it will appear in front of other sprites, but when I instantiate it through the line of code above it will not show up.

I don't know and am unable to find information on what the difference is between dragging and dropping it from the folder and using Instantiate().

  • Didin't you add that script to all objects accidentally? Is something that you Instatiated showing in the hierarchy? try: Debug.Log (Instantiate(bloodSpillEffect, transform.position, transform.rotation)); or: GameObject test = Instantiate(bloodSpillEffect, transform.position, transform.rotation) as GameObject; Debug.Log (test); If any of this returns null, it's mean that you instantiate that in the wrong way. – Konrad Jan 08 '16 at 23:17
  • It is instantiated and it is showing in the hierarchy. The problem is that it is showing behind all other sprites while it shouldn't be. – Dobromir Nikolov Jan 08 '16 at 23:19
  • Again, if I drag and drop it from the prefabs folder on the scene it will show above everything like it should, but if I instantiate it with Instantiate() it will show behind all other sprites. – Dobromir Nikolov Jan 08 '16 at 23:20
  • Isn't it caused by the fact, that you Instantiate that in the transform.position? – Konrad Jan 08 '16 at 23:24
  • transform.postion contains also z axis. – Konrad Jan 08 '16 at 23:26
  • Instantiate(bloodSpillEffect, new Vector3(transform.position.x, transform.position.y, -0.1f), transform.rotation); Doesn't seem to work either... – Dobromir Nikolov Jan 08 '16 at 23:31
  • So maybe Z axis is not the problem. – Konrad Jan 08 '16 at 23:33
  • Try adjust sorting layer of the partcile system. – Konrad Jan 08 '16 at 23:34
  • 1
    For some weird reason today when I tried it started working as intended. Thank you for your help! – Dobromir Nikolov Jan 09 '16 at 16:27

0 Answers0