Search Unity

Play particle system

Discussion in 'Entity Component System' started by shotoutgames, Oct 30, 2020.

  1. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    I instantiate a prefab as a child of a hybrid game object and then why I start the instance with particle system nothing happens?? Any idea what I am doing wrong? I see the cline as a child in the scene but it doesn't trigger when I want to.
     
  2. UsmanMemon

    UsmanMemon

    Joined:
    Jan 24, 2020
    Posts:
    87
    Hybrid renderer 0.9 added support for particle system(i believe). Just letting you know.
     
    apkdev likes this.
  3. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    Basically,
    conversionSystem.AddHybridComponent(comp)
    will do the job.
    But for ParticleSystem there is one extra hidden component ParticleSystemRenderer

    Code (CSharp):
    1.  
    2. using Unity.Entities;
    3. using UnityEngine;
    4. using System.Collections.Generic;
    5. using System.Linq;
    6.     [DisallowMultipleComponent]
    7.     [RequiresEntityConversion]
    8.     public class HybridComponent : MonoBehaviour, IConvertGameObjectToEntity
    9.     {
    10.         [SerializeField] protected List<UnityEngine.Component> Components = new List<Component>();
    11.  
    12.         public virtual bool IsNativeSupported(Component comp) =>
    13.             comp is Transform ||
    14.             comp is MeshRenderer ||
    15.             comp is MeshFilter ||
    16.             comp is SpriteRenderer ||
    17.             comp is UnityEngine.VFX.VisualEffect ||
    18.             comp is IConvertGameObjectToEntity ||
    19.             comp is ConvertToEntity ||
    20.             comp.GetType().Name.Contains("Authoring");
    21.  
    22.         protected virtual void Reset()
    23.         {
    24.             Components.Clear();
    25.             foreach (var comp in gameObject.GetComponents<Component>())
    26.             {
    27.                 if (IsNativeSupported(comp)) continue;
    28.                 else Components.Add(comp);
    29.             }
    30.         }
    31.  
    32.         private void OnValidate()
    33.         {
    34.             if (Components.Any(c => c is ParticleSystem) && Components.All(c => !(c is ParticleSystemRenderer)))
    35.             {
    36.                 var renderer = GetComponent<ParticleSystemRenderer>();
    37.                 if (renderer != null) Components.Add(renderer);
    38.                 else Debug.LogError("ParticleSystem referenced but ParticleSystemRenderer is missing!");
    39.             }
    40.         }
    41.  
    42.         public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    43.         {
    44.             foreach (var comp in Components)
    45.             {
    46.                 if (!comp) continue;
    47.                 if (comp is SkinnedMeshRenderer) continue;
    48.                 if (comp is Animator) continue;
    49.                 conversionSystem.AddHybridComponent(comp);
    50.             }
    51.         }
    52.     }
    Reset HybridComponent will trigger a new search for potential Components
     
    Last edited: Nov 4, 2020
    toomasio likes this.
  4. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    UnityEngine.VFX.VisualEffect is the new way of doing FX, It will be made HybridComponent by default.
    That's probably why ParticleSystem is not made HybridComponent automatically.
     
    shotoutgames likes this.
  5. kanesteven

    kanesteven

    Joined:
    Aug 30, 2018
    Posts:
    45
    @Lieene-Guo Thank you so much for your answer here. This would have wasted an insane amount of my time if not for your pro-tip about the ParticleSystemRenderer. Cheers.