Hi I am a begginer coder, I was following a tutorial to create a dialogue system by Sasquatch B Studios using Unity’s GraphToolkit. I got up to creating the choice node when I ran into the error CS0246 for INodeOptionDefinition. I have been attempting to fix this error for about 2 hours with no progress where I have looked through my project library to check if I am using the correct definition and used INodeOptionDefinitionContext in the errors place to no avail.
I am using Unity.GraphToolkit.Editor and UnityEngine.TestTools.Constraints within my code and have the latest version of both Unity and ToolGraphEditor installed.
The part of my code that is causing this error is below, with the namespace error being at the second to last line.
[Serializable]
public class ChoiceNode : Node
{
const string optionID = “portCount”;
protected override void OnDefinePorts(IPortDefinitionContext context)
{
context.AddInputPort("in").Build();
context.AddInputPort<string>("Speaker").Build();
context.AddInputPort<string>("Dialogue").Build();
var option = GetNodeOptionByName(optionID);
option.TryGetValue(out int portCount);
for (int i = 0; i < portCount; i++)
{
context.AddInputPort<string>($"Choice Text {i}").Build();
context.AddOutputPort($"Choice {i}").Build();
}
}
protected override void OnDefineOptions(INodeOptionDefinition context)
{
context.AddNodeOption<int>(optionID, defaultValue: 2, attribute: new Attribute[] { new DelayedAttribute() });
}
Not sure if you managed to come to the solution on your own.
I too am looking into the Graph Toolkit and saw the tutorial you mentioned.
I believe the problem you’re facing is down to the API changing. In early versions, the Graph Toolkit did have the INodeOptionDefinition interface.
However, this seems to have been removed in later versions, which can be found via the changelog (I would link it but we cannot post links…)
In the changelog for version 0.3 it states “Node Options are now defined via a builder, similar to ports.”, which means we have to now use a different syntax in our code to get the same behaviour as what is shown in the video tutorial.
Funnily enough, someone in the comments of the video posted the very solution we need:
As you mentioned you are new to coding so let me try to be helpful and explain the difference.
The function OnDefineOptions used to have the parameter INodeOptionDefinition but it now has IOptionDefinitionContext.
By swapping the parameter type in the function definition (thats line 17 in your code snippet) to be IOptionDefinitionContext, you will resolve the error in your original post.
To get the code working as you see in the video we need to follow the instructions given to us by the docs (define Node Options via a builder), that is what the line “context.AddOption(optionID).WithDefaultValue(2).Delayed();” is doing.
AddOption(optionID) is replacing AddNodeOption(optionID
.WithDefaultValue(2) is replacing , defaultValue: 2,
.Delayed(); is replacing , attribute: new Attribute[] { new DelayedAttribute() });
One final note for anyone else who stumbles across this post, as of Unity 6.4 Graph Toolkit is a module that comes with Unity, and we no longer need to install the experimental package via its name. There are experimental docs for versions 0.4 and below (with the changelogs that I mentioned earlier) which are outdated. Instead you will wanna go to the Unity Manual and search “Extending the Editor with Graph Toolkit” or simply “Graph Toolkit”.