What is the best way to set a value from editor script then use that value during runtime?

This is difficult to explain and the question might not reflect what I’m trying to accomplish so let me explain.

I have an editor script that creates a custom editor for an object that extends MonoBehaviour. The key feature this script allows is for the user to select a folder path using a native dialog window and it works perfectly. The way it does this is by overriding CreateInspectorGui();

When the user selects a folder, a TextField property, that exists on the editor script, has it’s value set to the chosen folder’s path, great, works perfectly.

Now, what I want to do, is when the app is running, use that value that path that they’ve chosen to save a file in that location. I know how to do that, my problem is that I don’t know how to transfer that path they’ve chosen to runtime? Is there an existing solution to this?

I almost feel like maybe I’m going about this the wrong way, like maybe I should move over the folder selection to be all in runtime but it’s not really a runtime thing because this app is an app only used in the production of another, user facing, app.

I’m a bit confused. Where exactly are you storing that selected path? You said you created a custom editor for your monobehaviour class. So a custom editor is for editing fields of that object it is inspecting. So your monobehaviour derived class instance. Doesn’t this class have a string field to hold that path you’re interested in?

I’m also not sure what you mean by “TextField property”. TextField is a method of the IMGUI system to show a text field which allows to edit a string in the GUI. The string you want to edit should be a field / serialized property of the monobehaviour you’re editing with your custom editor. A custom editor should not store any persistent state inside itself, only temporary information. As soon as you deselect the object inspected, the editor would be destroyed / reused by the next object you select. So from your description it sounds like you’re doing something fundamentally wrong here ^^.

The new UIElements system is a bit more complex, so it’s difficult to follow what you actually did without seeing the code. Generally UIElements can have a binding to a certain serializedproperty of a certain object. That object should be the object you’re inspecting and the property path of the binding should reference the field of that monobehaviour object that this text field should edit.

Using the classic IMGUI approach is probably easier to follow what is happening. Though that’s not generally necessary. However without more information about your exact usecase I’m not sure how we should answer this question clearly since your current behaviour is not really clear, at least not to me.

Okay let me try explaining again, and it could very well be that I’m not going about this the correct way, that’s kinda what I’m asking. However, it seems like I may have explained it poorly because honestly, it’s not a very complicated thing I’m trying to accomplish.

My “application” is really two applications, two separate projects. The first project is the app used by the developer to create a world that is serialized and saved and is then used in the second app, the user app.

So, what I need to do is give the developer a way to set the path where the data will be saved for the user app. To do this, I just created a custom inspector and via UI Toolkit UI Builder, I added a TextField in the custom inspector. In the actual scene of the dev app, is a button to “save” the data. When the dev app is running and the developer clicks the save button, the app should save the data using the path specified. Now, this path is set in the inspector which means I don’t know if I can access it during runtime like I’m imagining.

That’s why I’m here, because my problem is kind of unique. I guess I could make it not in the inspector and instead part of the scene itself in a UI element. I guess that’s the best way. I’ll have to look into how to show a folder selection dialog during runtime.