Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
23
Question by Shannon Archer · Nov 17, 2013 at 06:49 AM · 2dspriteparticles

Particle System rendering behind Sprites

I'm trying to use a particle system with my 2d project.

I have it placed on a higher z-index and can see it when the particle systems materials shader is bumped diffuse, however when I change it to something like unlit/transparent it will always render behind the sprites regardless of what the z-index of the particle system is.

Since there isn't many resources on working with 2d in 4.3 is there something I don't know about particle systems or the new 2d stuff that is causing this issue?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image supernat · Nov 17, 2013 at 09:32 PM 0
Share

I haven't played with the new 2d system yet, but it sounds like the order of the object in the render queue is different between the different shaders. You can either set the $$anonymous$$aterial.renderQueue via script or hard code it in the shader, if you create your own shader or downloaded the default shaders source. I can't guarantee it will fix the problem, but moving the renderQueue to say something like 4000 may work. The 2D sprites are probably drawn in the transparent queue range, same as particles, so that may solve the issue.

avatar image Shannon Archer · Nov 18, 2013 at 01:13 AM 0
Share

I tried changing the particle materials render queue to 4000 but it hasn't changed anything and I'm not sure I want to start digging into the shaders source.

avatar image maxmadman · Jul 09, 2014 at 05:40 AM 0
Share

Hi, I don't know if this thread is still open, but I am having the same issue with HALO effect. $$anonymous$$y halo effect is not visible when I have background game object, but if I dragged the background game object out of the view, the HALO effect is shown properly.

I tried different things suggested by answer.unity from adding new script to add sorting layer manager to adding codes as suggested here, but none of them are working. When using adds on for sorting layer manager, only game object shown on the list, but the halo effect is not shown as separate entries on sorting layer manager. When displaying in 3D, it shows correctly that the sprites and halo are located between camera and background texture, but it won't be shown at all on both game and scene windows. Any idea how to fix it?

The way I structured my game is one background game object, prefab containing 4 child game objects, and halo effect attached to all 4 child game objects. Because they are children, Unity won't allow me to add additional game object under the children for the halo. Any help is appreciated!

Thanks! Eric

16 Replies

· Add your reply
  • Sort: 
avatar image
29
Best Answer

Answer by Stone-Legion · Nov 23, 2013 at 10:09 AM

Figured it out. It seems odd you have to go this far but here's the solution.

On the Particle System object you've created, create a C# script and name it "ParticleSortLayerScript" or whatever else you want to call it. You can also add this into your code if you have a script attached but make sure it gets added to the Start() method.

Now you have to manually code in what layer you want the particle system to apply to. It seems that by default, the particle system gets sent behind every other layer, which is why you have to force it to be in a layer in front for the camera to see.

Code to do this is:

     void Start ()
     {
             //Change Foreground to the layer you want it to display on 
             //You could prob. make a public variable for this
             particleSystem.renderer.sortingLayerName = "Foreground";
     }

Note that for my project Foreground is the name of the layer I want my particles to display, but yours may be different. If you dont know what I mean by Layer, I'm talking about sorting layers. On the Top right of the Unity Editor you should see a drop down called "Layers", click this to see the layers in your project. You can add additonal layers if you like as per http://docs.unity3d.com/Documentation/Components/Layers.html

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ImpishMario · Nov 23, 2013 at 02:54 PM 0
Share

You're right about sorting layers, I also use it to render various object properly in 4.3. However, for reasons unknown, I can't get this working with lights (halo, point, etc). I set the correct layer via script and it works with any object but lights seem to be rendered always "under" the texture (see attached screenshot).

alt text

Any idea how to fix it?

light.png (145.0 kB)
avatar image aburningflame · Jan 25, 2014 at 09:46 PM 0
Share

Thanks - this helped me. You can also do this @ instantiation time ins$$anonymous$$d of adding a script to the particile system.

     if (deathAnimation!=null){
     GameObject ps=(GameObject)GameObject.Instantiate(deathAnimation);
 ps.transform.position=transform.position;
 ps.renderer.sortingLayerName="Foreground";
     }
avatar image Kytin · Jul 05, 2014 at 04:44 AM 0
Share

I have been struggling with this problem for ages. Your fix wasn't working for me.

It turns out that if you have your particleSystem component on an object that also has a sriteRender component then particleSystem.renderer will actually return the render for the sprite, rather than for the particleSystem.

I was able to work around the issue by creating a separate object for the particleSystem and making it a child of the original object.

avatar image Hazlo · Jul 28, 2014 at 12:28 PM 0
Share

Thank you for the solution!

avatar image Mikael-H · Aug 03, 2014 at 07:00 PM 1
Share

In order to stay away from hardcoding layers I did this:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(SpriteRenderer))]
 [RequireComponent(typeof(ParticleSystem))]
 public class SetParticleRenderLayerScript : $$anonymous$$onoBehaviour {
 
     // Use this for initialization
     void Start () {
         SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
         particleSystem.renderer.sortingLayerID = spriteRenderer.sortingLayerID;
         particleSystem.renderer.sortingOrder = spriteRenderer.sortingOrder;
     }
 
 }
 

This allows me to add a spriterenderer to the particle system prefab and set the layers in that ins$$anonymous$$d.

Show more comments
avatar image
61

Answer by KonkyBean · Mar 10, 2015 at 09:47 AM

Not sure if this was in Unity 4.6, but in Unity 5, go to your particle's Inspector, expand "Renderer" and you should see the fields "Sorting Layer" and "Order in Layer" (close to the bottom). Select the sorting layer that you wish the particles to appear on.

This fixed my issue (particles appearing behind background) and hopefully it'll fix yours.

Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheWarper · Mar 10, 2015 at 09:52 AM 0
Share

O good, glad to hear they added this, Thanks $$anonymous$$onky!

avatar image KonkyBean · Mar 10, 2015 at 10:29 AM 0
Share

No worries, mate, glad to help :)

avatar image Justin_H · Apr 01, 2015 at 03:46 PM 0
Share

I was having the same problem and this solution worked for me. No script writing needed. Thank you friend!

avatar image Baalzamon · Apr 15, 2015 at 07:43 AM 0
Share

Thank you! This should really be the top-voted answer.

avatar image Nikovich · May 07, 2015 at 03:02 PM 0
Share

This feature isn't available in Unity 4.6, let alone 4.3

Show more comments
avatar image
3

Answer by KarmaAdjuster · Apr 16, 2017 at 08:46 AM

I encountered a similar problem but for seemingly entirely different reasons. The problem was made clearer when I switched from viewing the scene in 2D to 3D. The issue was that that particle system was emitting the particles AWAY from the camera, and thus behind all of the other sprites in the scene.

My solution was to set either the X or Y rotation to 180 degrees.

Edit: Oops. I replied twice. I couldn't see that I had replied, and just assumed the website ate my comment.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Panx · Jan 22, 2014 at 06:25 AM

I just ran into this same issue, and swore up and down it was sprite-related, since that was the last thing I added to my project.

However, I just realized I'd been calling Play() and Stop() on every Update() cycle, rather than just once and letting them do their thing.

This was also causing my particle system to fail to start (unless it started pre-warmed for some reason).

Just a thought, if someone else stumbles into this thread and can't get the above green-answer to work for them.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by ManiacPyro101 · Aug 19, 2014 at 07:34 AM

It seems that particles like to be seen in the 0 sorting layer, so what i have done is put my 2D content in -1,-2 layers, this should fix your problem

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syamilsynz · May 06, 2015 at 04:37 AM 0
Share

work for me

  • 1
  • 2
  • 3
  • 4
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

46 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

make rain with sprite sheet in unity2d 2 Answers

In-Game 2D Sprite Building System 0 Answers

Particles - start speed curve doesn't work? 1 Answer

Sprite renderer, bad perfomance on mobile 1 Answer

How to detect the distance between two edges (2D sprites) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges