- Home /
How do you get the rootElement for the SettingsProvider.activateHandler property?
So I'm trying to save data for a custom editor window and have recently discovered SettingsProvider and I'm trying to understand how to use it (The version meant for UIElements). I have a basic grasp of UIElements but this thing has got me stumped. The documentation makes it seem like you show have access to the root but it's not the cause.
Below, I'm trying to using the activeHandler property to override SettingsProvider.OnActivate() as described in the documentation (which is was its description says it's for) but it requires a visual element. When I create my own, it throws an error when assigning to the property (Cannont implicitly convert type '(string, UnityEngine.UIElements.VisualElement root)' to 'System.Action< string, UnityEngine.UIElements.VisualElement>') so I'm guessing you need to pass the actual root element for the settings window. Does anyone know how to do this? Or if this isn't how you use this, how are you supposed to do this?
Edit: Missed part of the error message.
using System.IO;
using UnityEngine.UIElements;
using UnityEditor;
namespace ACTools
{
namespace DataManager
{
class DataManagerSettingsProvider
{
public static bool IsSettingsAvailable()
{
return File.Exists(DMDPaths.MyPath);
}
[SettingsProvider]
public static SettingsProvider CreateDataManagerSettings()
{
if (IsSettingsAvailable())
{
VisualElement root = new VisualElement();
SettingsProvider provider = new SettingsProvider("ACTools/Data Manager", SettingsScope.Project)
{
label = "Data Manager",
activateHandler = ("Data Manager", root),
};
return provider;
}
return null;
}
}
}
}
Answer by clinealex10 · Jul 30, 2019 at 01:08 PM
I think I figured out it out. It seems that you need to have "activateHandler = (searchContext, rootElement)" instead of having your own string and visual element like "activateHandler = ("Data Manager", root)". My guess is that searchContext and rootElement are just names you assign to parameters you can manipulate below, thus they need to not exist before you assign them. So you could name these two parameters anything you'd like.
Edit: "activateHandler = (searchContext, rootElement)" is actually in the SettingsProvider Scripting API page so if you just follow that, it should work.