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
#2
Hi,
What is the message of the errors?
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply
#3
And I don't see the need to implement IOnRequestPath, especially that you don't implement its methods, and that your module does not provide a path. Try remove the IOnRequestPath implementation
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply
#4
The bug seems to have disappeared miraculously. I removed IOnRequestPath and its methods, and that seemed to do the trick. So for making your own module, it is enough to pass the output arguments in Refresh()?

If something strange happens, you'll be the first to know. Thanks for the support!
Reply
#5
The bug was probably because you used the interface without implementing its methods.
Yes, setting data in refresh is enough.
Have a nice day
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply
#6
The bug was probably because you used the interface without implementing its methods.
Yes, setting data in refresh is enough.
Have a nice day
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Errors in Built Application in CurvySplineSegment TdayMFG 7 203 04-13-2025, 09:24 AM
Last Post: _Aka_
  Updated package in 2022 LTS resulted in multiple errors scr33ner 2 223 01-13-2025, 09:32 AM
Last Post: _Aka_
  Small errors in end tangents, by davelloyd _Aka_ 0 109 01-07-2025, 11:14 AM
Last Post: _Aka_
  Playmaker setup errors and missing scripts? justifun 9 747 08-06-2024, 09:41 AM
Last Post: _Aka_

Forum Jump: