Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by benarceneaux0 · Dec 15, 2021 at 11:27 AM · editorguicustom-inspector

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 15, 2021 at 12:46 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by benarceneaux0 · Dec 16, 2021 at 10:05 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

136 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to achieve proper inspector functionality (blue highlight of last tweaked) with elements from the GUI class (not from EditorGUI) 1 Answer

Prefix label greyed out when following component disabled 1 Answer

Object field not working in custom editor for scriptable object? 0 Answers

How to add custom ui on top control panel 1 Answer

drawdefaultinspector except of one variable?? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges