Search Unity

Sterilize IComponentData in the editor

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Jun 26, 2019.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    Wait ..can u sterilize IComponentData into the editor ? How ?
     
  2. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    do you mean sanitize? you can perform sanitisation steps in the convert method of IConvertGameObjectToEntity before you create the component

    Code (CSharp):
    1.   [Serializable]
    2.   public struct SomeComponent : IComponentData {
    3.     public int Value;
    4.   }
    5.  
    6.   [RequiresEntityConversion]
    7.   public class SomeComponentProxy : MonoBehaviour, IConvertGameObjectToEntity {
    8.     // can be used to restrict Value
    9.     [Range(0, 2)]
    10.     public int Value;
    11.  
    12.     public void Convert (Entity entity, EntityManager em, GameObjectConversionSystem conversionSystem) {
    13.       // sanitize value here
    14.       em.AddComponentData(entity, new SomeComponent {
    15.         Value = Value
    16.       });
    17.     }
    18.   }
    or you must have meant serialize?

    they used to have ComponentDataProxy for that but now the IConvertGameObjectToEntity allows you to have full editor support, then just convert the editor data to blittable data for the components
     
    Last edited: Jun 26, 2019
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    Ok thanks for the reply. I read on web it was live outside of subscens but I guess not yet
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    SubScenes aren't required for IConvertGameObjectToEntity
     
  5. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    Yup got IConvertGameObjectToEntity working , what is really killing me it the live link. I get all sort of weird stuff like duplicate entities and save button greyed out