Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rhys-vdw opened this issue May 13, 2022 · 3 comments

Comments

@rhys-vdw
Copy link

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

@rhys-vdw rhys-vdw changed the title Calling AddExposedParameter in BaseGraph.OnEnable causes all ports to disappear. Calling AddExposedParameter in BaseGraph.OnEnable causes all ports and edges to disappear. May 13, 2022
@rhys-vdw
Copy link
Author

rhys-vdw commented May 13, 2022

Okay, I think I've worked it out. If I explicitly override GetValueType() in my exposed parameter subclass then the error goes away. Given this I would suggest that the base method should be abstract instead of virtual (or just fix the bug whatever is causing it).

@rhys-vdw
Copy link
Author

I was wrong, the issue is back. I am really unsure what's causing it.

@rhys-vdw
Copy link
Author

Okay, seems this was caused by a failure to call base.OnEnable()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant