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
1
Question by Stradigos · Mar 16, 2012 at 04:26 AM · editorspawnruntimevariablesinitialize

Getting data from Editor into runtime

The Setup

I just spent a week writing some editor code that allows me to place spawn points around my map (in the editor).

The editor script, SpawnEditorWindow, resides in the Editor folder.

The manager for that script, called SpawnPointManager (resides outside Editor folder), is connected to an empty game object in my scene.

Also connected to that empty game object is another script called SpawnManager, which communicates with my in-game pauseMenu to spawn all the characters in the map at runtime.

SpawnManager draws information from SpawnPointManager, which in turn figure out how many spawns there are from SpawnEditorWindow (basically, from the editor slider bars).

The Problem

So, on to my problem... This works beautifully inside the editor. I hook everything up, open the spawn editor window, adjust how many spawns I want, position them, etc.

However... when I go to run this, the List those spawns isn't initalized... or maybe it's reintialized, I don't know. Anyway, the List count is zero, thus no spawns exist.

The Question

What are my options here? How can I get this information into runtime? It's a List.

Comment
Add comment · Show 1
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 syclamoth · Mar 16, 2012 at 04:28 AM 1
Share

$$anonymous$$ake sure that all the relevant information is being stored in serialized objects in the scene. Information that is only in the editor window will be lost whenever the scripts reload.

2 Replies

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

Answer by PaxNemesis · Mar 16, 2012 at 03:37 PM

If you put your own custom class into a list it have to be Serialized not to disappear. So if you have a custom SpawnPoint script you need to use the [System.Serializable] attribute:

 [System.Serializable]
 public class SpawnPoint : MonoBehaviour
 {
     // Stuff you want to do.
 }
 
 public SpawnPointManager : MonoBehaviour
 {
     public List<SpawnPoint> spawns = new List<SpawnPoint>();
 
     // Do the rest of your stuff.
 }
Comment
Add comment · Show 1 · 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 Stradigos · Mar 17, 2012 at 06:26 AM 0
Share

Thanks for the snippet and the explaination. Your tip about the custom class list was spot on. It's working now, thanks!

PS: Anyone reading this in the future may want to know that I had to delete the game objects and reattach my scripts after this for it to recognize it. Not sure why.

avatar image
0

Answer by DaveA · Mar 16, 2012 at 07:16 AM

You could have a game object with a script containing a List and have your editor script Find it and copy to it.

Comment
Add comment · Show 1 · 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 Stradigos · Mar 16, 2012 at 02:19 PM 0
Share

That's actually how it's set up now. SpawnPoint$$anonymous$$anager (records spawn points) and Spawn$$anonymous$$anager (what actually manages the spawning), are both attached to an empty game object. The editor script is finding the SpawnPoint$$anonymous$$anager script and setting that game objects position (the spawn node) to what the slider in the editor window says. No dice.

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

7 People are following this question.

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

Related Questions

Custom Inspector Variables 1 Answer

Execute editor window scripts when project errors are present 0 Answers

Make New GameObject From Menu Spawn At Zero 4 Answers

Addressables.InitializeAsync no work run time 0 Answers

Adapt variables based on other variables... confusing 1 Answer


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