Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 shimauma · Apr 16, 2015 at 05:05 PM · editor

How to save set values of an instantiated prefab BEFORE runtime programmatically?

Hello.

I am trying to populate a two ints and a list of monobehaviour scripts for a pathfinding before runtime (from an Editor script) since I don't wanna calculate which nodes are connected in runtime (requires too much computing and will lag every time the scene loads).

 public class TileNode : MonoBehaviour, IPoint
 {
     public int xCoord = 0;
     public int yCoord = 0;
     public bool isWalkable = true;
     public List<TileNode> Connections = new List<TileNode>();
 ...

Here's the IPoint interface in case it matters:

 public interface IPoint
 {
     int X { get; }
     int Y { get; }
 }

Basically in short, what I want it so do this drag and drop: alt text

except with code instead of manually drag&dropping everywhere.

EDIT/UPDATE: Okay so I managed to populate the X and Y and the List programmatically in Edit Mode (i.e. not runtime), but when I press PLAY, the ints X and Y keep their values, but the list's values disappear. How do I make sure my programmatically added List values don't get lost on the instantiated object upon pressing PLAY?

(I guess a possible(?) solution would be to programmatically create scriptableobjects that hold the necessary information, but I wanna avoid that if possible.)

Comment
Add comment · Show 3
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 spiceboy9994 · Apr 16, 2015 at 05:49 PM 0
Share

Isn't the Awake method suitable for you?, The Awake method is called when the script is loaded.

http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.Awake.html

Regards

avatar image Owen-Reynolds · Apr 16, 2015 at 08:45 PM 0
Share

I think they want to pre-compute this in edit mode, so that running the game won't compute it at all. If so, yes, that's an Editor Script.

Sound like merely "how to properly save Editor Script variables."

avatar image shimauma · Apr 17, 2015 at 12:30 AM 0
Share

Owen: Yes kind of, but maybe not quite, since the variables are set in a monobehaviour class and not in an editor class. The editor class does the setting, but it's not the class that saves the values - it merely applies the values to the monobehaviour scripts' lists.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by shimauma · Apr 17, 2015 at 09:58 AM

I found a solution myself to this, so reporting it here if anyone comes across this question. The problem was that I need to call "EditorUtility.SetDirty()" on the objects that I changed (i.e. added a list value).

http://forum.unity3d.com/threads/custom-editor-losing-settings-on-play.130889/

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

19 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

Related Questions

Why my Roguelike 2D graphics are naughty in devices? 1 Answer

Left Click Up Event in Editor 4 Answers

EditorWindow texture effected by Playmode Color Tint 1 Answer

Spline Editor: Maintain object selection and object attachments 0 Answers

how to keep static variables or 2d array value 0 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