Skip to content

Calling AddExposedParameter in BaseGraph.OnEnable causes all ports and edges to disappear. #214

@rhys-vdw

Description

@rhys-vdw

I'm trying to create a system where I can ensure that certain graph types always expose the correct properties.

My base node with helper:

using GraphProcessor;
using System.Linq;
using UnityEngine;

namespace EffortStar {
  public class ESBaseGraph : BaseGraph {
    protected void EnsureParameter<T>(string name, object value = default) where T : ExposedParameter {
      var existing = exposedParameters.Find(p => p.name == name);
      if (existing != null) {
        if (existing.GetType() != typeof(T)) {
          RemoveExposedParameter(name);
        }
      }
      if (existing == null) {
        AddExposedParameter(name, typeof(T), value);
      }
    }
  }
}

Example graph:

using GraphProcessor;
using System.Linq;
using UnityEngine;
using System;

namespace EffortStar {
  using Events;

  [Serializable]
  public class ActorEventParameter : ExposedParameter {
    [SerializeField] ActorEvent _value;

    public override object value {
      get => _value;
      set => _value = (ActorEvent) value;
    }
  }

  [Serializable]
  public class EventContextExposedParameter : ExposedParameter {
    [SerializeField] EventContext _value;

    public override object value {
      get => _value;
      set => _value = (EventContext) value;
    }
  }

  [CreateAssetMenu(menuName = "EffortStar/Graph/ActorEventGraph")]
  public class ActorEventGraph : ESBaseGraph {
#if UNITY_EDITOR
    protected override void OnEnable() {
      EnsureParameter<ActorEventParameter>(nameof(ActorEvent));
      EnsureParameter<EventContextExposedParameter>(nameof(EventContext));
    }
#endif
  }
}

New graph created with correct exposed parameters:
image

Adding some nodes:

image

Close and reopen graph editor:
image

Possibly related to #155

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions