Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by gianlucag · Nov 21, 2019 at 10:49 AM · shadersassetbundleparticlesystem

Particle System loaded from Asset Bundle not rendering in Editor

Hi everyone!

I’m having a problem with a prefab loaded at runtime from an AssetBundle.

This prefab contains a ParticleSystem that doesn’t show up in the editor.

If during playmode I select the game object, I can see that the PS is emitting, but it doesn’t show in the game view, and appear as empty quads in the Scene view.

If select the PS and open its material properties in the inspector, the particles magically start to show up.

The PS uses Default-ParticleSystem material and Particles/Standard Unlit shader. In the material properties it has a warning saying that I use the incorrect vertex streams , but it works fine in another scene.

I am aware that there are issue with shaders and material loader from a bundle, so as a workaround I re-assign the shader when I instantiate the prefab, and I put it in the “Always included” shader list. The PS works fine on target mobile device (iOS/Android platforms).

Here is the code I use to fix the material/shaders :

      ...
         //It's obviously not named like this, but let's just say it's a reliable way to get the 
     `//`prefab from the bundle as an Object
         UnityEngine.Object asset = GetThePrefabFromTheBundle();
            
     if (null != asset)
            
     {
        
             GameObject reqPrefab = (GameObject)asset;
        
   //m_target is a member variable of Component type that I know it's a transform in this case 
                Transform t = (Transform)m_Target;
                
     GameObject instance = Instantiate(reqPrefab, t);
             //m_offset is a class member Vector3 variable
                
     instance.transform.localPosition = m_offSet;
                
     FixParticleShaders(instance);
            
     }
            
         ....
         
         
         
         private void FixParticleShaders(GameObject i_gameobject)
         {
         #if UNITY_EDITOR
             ParticleSystemRenderer[] particles = i_gameobject.GetComponentsInChildren<ParticleSystemRenderer>();
         
             for (int i = 0; particles.Length > i; i++)
             {    
                 Material mat = particles[i].sharedMaterial;
                 FixupShader(mat);
         
             }
         #endif
         }
         
         
         private void FixupShader(Material i_material)
         {
         #if UNITY_EDITOR
         
             if ((RuntimePlatform.OSXEditor == Application.platform)
             || (RuntimePlatform.WindowsEditor == Application.platform))
             {
                 if (null != i_material
                 && null != i_material.shader
                 && !string.IsNullOrEmpty(i_material.shader.name))
                 {
                     string shaderName = i_material.shader.name;
                     Shader sh = Shader.Find(shaderName);
                     if (null != sh)
                     {
                         i_material.shader = sh;
                     }
                 }
             }
                 
         #endif
         }

What am I doing wrong?

PS: Sorry for the horribly formatted code, but the textbox here doesn't help much

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

202 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 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 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 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 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

Importing particles at runtime with Asset Bundles 1 Answer

Diffusion profile doesn't work in asset bundle 0 Answers

Why does adding shaders to "Always Included Shaders" in graphics settings increase asset bundle size? 0 Answers

Custom shaders not loaded with asset bundle. 1 Answer

Make Custom Particle Shader interact with Particle System parameters 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