Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom module spits a lot of errors
#1
Hi,

I'm trying to make a custom module that I can use in the Generator graph. It takes some spots, filters them, and then returns new spots based on a filter.
Sadly, I get a lot of errors in Curvy scripts (dictionary key not found, nullrefs, etc.). What am I doing wrong?
My code:
Code:
using System;
using UnityEngine;
using FluffyUnderware.DevTools;
using System.Collections.Generic;
using FluffyUnderware.Curvy.Generator.Modules;
using UnityEditor;

namespace FluffyUnderware.Curvy.Generator.Modules
{
   [ModuleInfo("Build/Filter Spots", ModuleName = "Filter Spots", Description = "Filter spots based on position", UsesRandom = false)]
   public class CurvySpotFilter : CGModule, IOnRequestPath
   {
       [HideInInspector]
       [InputSlotInfo(typeof(CGSpots), Name = "Spots to Filter", DisplayName = "Spots")]
       public CGModuleInputSlot InSpots = new CGModuleInputSlot();

       [HideInInspector]
       [OutputSlotInfo(typeof(CGSpots), Name = "The spots filtered after filter function", DisplayName = "Filtered Spots")]
       public CGModuleOutputSlot OutSpots = new CGModuleOutputSlot();

       #region ### Serialized Fields ###
       
       [SerializeField, Label("Filter Function", Tooltip = "Filter Function defined in CurvySpotsFilters.cs")]
       SpotFilterType filterFunction;

       #endregion

       #region - General Tab -

       public SpotFilterType FilterFunction
       {
           get { return filterFunction; }
           set
           { filterFunction = value; }
       }

       public float PathLength => throw new NotImplementedException();

       public bool PathIsClosed => throw new NotImplementedException();



       #endregion


       #region ### Unity Callbacks ###
       /*! \cond UNITY */

       protected override void OnEnable()
       {
           base.OnEnable();
           Properties.MinWidth = 350;
       }

#if UNITY_EDITOR
       protected override void OnValidate()
       {
           base.OnValidate();
           FilterFunction = filterFunction;
           Dirty = true;
       }
#endif

       public override void Reset()
       {
           base.Reset();
           FilterFunction = 0;
       }

       /*! \endcond */
       #endregion

       public override void Refresh()
       {
           base.Refresh();
           List<CGSpot> filtered = new List<CGSpot>();
           CGSpots all = InSpots.GetData<CGSpots>();
           for (int i = 0; i < all.Count; i += 1)
           {
               CGSpot spot = all.Points[i];
               if (!CurvySpotFilters.Filter(filterFunction, spot.Position))
               {
                   filtered.Add(spot);
               }
           }
           CGSpots spotsOut = new CGSpots(filtered);
           OutSpots.SetData(spotsOut);
       }

       public CGData[] OnSlotDataRequest(CGModuleInputSlot requestedBy, CGModuleOutputSlot requestedSlot, params CGDataRequestParameter[] requests)
       {
           if (requestedSlot == OutSpots)
           {
               List<CGSpot> filtered = new List<CGSpot>();
               CGSpots all = InSpots.GetData<CGSpots>();
               if (all != null)
               {
                   for (int i = 0; i < all.Count; i += 1)
                   {
                       CGSpot spot = all.Points[i];
                       if (CurvySpotFilters.Filter(filterFunction, spot.Position))
                       {
                           filtered.Add(spot);
                       }
                   }
                   CGSpots spotsOut = new CGSpots(filtered);
                   OutSpots.SetData(spotsOut);

                   return new CGData[1] { spotsOut };
               }
           }
           return null;
       }
   }
}

Editor:
Code:
using UnityEditor;
using FluffyUnderware.Curvy.Generator.Modules;

namespace FluffyUnderware.CurvyEditor.Generator.Modules
{
   [CustomEditor(typeof(CurvySpotFilter))]
   public class CurvySpotFilterEditor : CGModuleEditor<CurvySpotFilter>
   {  }
}

The script CurvySpotFilters.Filter(filterFunction, spot.Position) is working as it should. I can implement the module the first time, but if I try to reopen the graph, it starts spitting errors. Sometimes the input node also taken 2 inputs for some reason (two lines are drawn towards it?) and I am unable to draw an edge from the output node.

It would be really convenient to have a tutorial on how to make a simple custom module, by the way.

Thanks in advance!
Reply


Messages In This Thread
Custom module spits a lot of errors - by Tim1234 - 10-23-2019, 12:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to attach custom components to output Sacryn 3 7 02-23-2024, 09:42 AM
Last Post: _Aka_
  Collider doesn't get created by the CreateMesh Module pako88 5 10 12-26-2023, 11:13 AM
Last Post: _Aka_
  Guide to custom placing stuff on spline Lupos 15 43 11-27-2023, 12:51 PM
Last Post: _Aka_
  Custom CurvySplineSegment prefabs Lupos 1 10 10-02-2023, 09:36 AM
Last Post: _Aka_

Forum Jump: