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?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
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
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
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
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
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
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Extrude custom mesh along a path CesarGenera 3 225 09-19-2019, 04:47 PM
Last Post: _Aka_
  Permission to publish custom CGModule source code? Apelsin 5 4,076 01-13-2019, 03:23 PM
Last Post: NicholasBosworth
  Custom connection controller help dazz777 6 2,833 11-21-2018, 11:26 AM
Last Post: _Aka_
Bug if part of curvy hierarchy is selected, but root is not enabled, errors happen hawken 2 2,043 01-15-2018, 01:27 PM
Last Post: _Aka_

Forum Jump: