Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Tom 17 · May 25, 2011 at 02:00 PM · editor-scriptingtestingplaymodeconcurrency

Concurrency and editor scripts and the play mode

Update:

I solved the issue and detailed the whole automated smoke test process here: Answer to Continuous Integration with Unity?


Original post:

This question is related to this one: Programmatically playing a scene for a single frame

The core issue I want to address is that it seems impossible to stop a running game from a seperate thread. I use an editor script to setup a scene and run it using

EditorApplication.isPlaying = true

  • I manage to signal the end of a frame but I can't access EditorApplication from a seperate thread (error at runtime). This is normal as with most game engines some things must stay synchronized over the main thread

  • If I try to block the editor script (OnGUI/Update) this results in a deadlock of the whole application

  • If I start the playmode paused and try to do just one step (EditorApplication.Step()) I never get the signal (i.e. yield return new WaitForEndOfFrame(); never returns)

Are there any other ideas to try? Otherwise I will stick to having to run an abitrary number of frames as prescribed in the linked Q&A.

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

1 Reply

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

Answer by Bunny83 · May 25, 2011 at 02:52 PM

You can't and shouldn't access any unity api from another thread. The Unity api only works in the main thread (or the thread that fires your events). You can use threads to do your own stuff but you can't use the api. The only thing that works so far is Debug.Log() ;) but i'm not sure if it's even thread safe

Comment
Add comment · Show 7 · 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 Bunny83 · May 25, 2011 at 02:59 PM 0
Share

I discovered that Unity needs some frames until everything is initialized. That's not a constant amount. It depends on many things like: is the gameview visible or not, is "maximize on run" on. I would run at least 20-50 frames. When pressing "play" unity saves the current state of the scene so it can revert the changes made at runtime.

avatar image demize2010 · May 25, 2011 at 03:02 PM 1
Share

http://forum.unity3d.com/threads/17721-Unity-threads from Aras on the matter.

avatar image Tom 17 · May 25, 2011 at 03:04 PM 0
Share

Yeah, you are right. I posted this question in an effort to highlight one aspect of the issue I linked to. If WaitForEndOfFrame would work in conjunction with Step() I wouldn't have to try employing seperate threads at all.. I'll give you the karma for your answer, through :-)

avatar image Bunny83 · May 25, 2011 at 03:06 PM 0
Share

If you need to execute your code at edit-time you can use the delegate "update"
http://unity3d.com/support/documentation/ScriptReference/EditorApplication-update.html
As far as i remember it is called 100 times per second.

avatar image Tom 17 · May 26, 2011 at 09:35 AM 0
Share

Now I only need to figure out how to do all this in batchmode. The batchmode quits when the static method quits. If I don't use -quit on the command line the playmode still seems not to trigger, but I need to play around a bit more to be sure - and maybe file another question :D

Show more comments

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

2 People are following this question.

avatar image avatar image

Related Questions

Is there a limit to Test Runner play mode test duration? 2 Answers

DestroyImmediate(component.gameObject) destroys component but not gameObject 1 Answer

TestRunner playmode timeout (?) 3 Answers

Play mode testing stalled 0 Answers

Enter play mode from editor script after baking is complete 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