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 OmegaVemon · Nov 21, 2010 at 07:15 PM · scenefunctionstartinitializemain

"Main" function?

I'm new to Unity! (though I'm getting the hang of it pretty fast!)

Anyway, in the past I have scripted many games in other languages and platforms, and I'm sure Unity is no exception here: Every game basically has a "Main" loop, where everything happens: Updating all the game objects, processing data like input etc...

I am wondering, where might I access the equivalent to such "Main" function in Unity? I am assuming each scene has its own Main or Update function, but I'm having trouble finding it.

I wish to do a few things when a scene loads.

Well, that's not a big problem for my project right now, because I could simply create a new GameObject and put those things in the Awake() function or something, and ta-da. But I was wondering if there is a more "official" way to do things on scene initialization.

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

3 Replies

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

Answer by Eric5h5 · Nov 21, 2010 at 07:18 PM

There is no Main function in Unity; everything is component-based. Your solution (create an empty game object with a manager script attached) is the usual way of handling scene-wide initialization.

Comment
Add comment · Show 3 · 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 OmegaVemon · Nov 21, 2010 at 07:20 PM 0
Share

Oh well, that sounds good enough to me, thanks!

avatar image Eric5h5 · Nov 21, 2010 at 07:24 PM 0
Share

It may seem odd at first, but after using Unity for a couple of years or so, the concept of a $$anonymous$$ain function seems backwards and limiting now.

avatar image OmegaVemon · Nov 21, 2010 at 07:39 PM 0
Share

After using Unity for a couple of days or so, the lack of a $$anonymous$$ain function is a bit desperate. But I'll get used to it =D

avatar image
-1

Answer by John Hamill · Jan 31, 2011 at 07:38 PM

How do you make a certian scene load first then?

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 Eric5h5 · Jan 31, 2011 at 11:33 PM 0
Share

This isn't an answer; please start a new question.

avatar image
0

Answer by BurningThumb · Nov 21, 2010 at 09:37 PM

Having a Main() function would defeat the purpose of having an engine.

The engine is started by main and form there it calls the functions here when they are required:

http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.html

If you are familiar with object oriented programming(which is in the best interest of all developers) understand that that for every script you make you also create a class by its name. When the engine calls update it calls MonoBehaviour.Update() in everyone of your classes.

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

No one has followed this question yet.

Related Questions

Creating a scene using script (which Start() to use) 2 Answers

How do i initialize only once for a scene? 1 Answer

Declare array in other function = error 1 Answer

Start menu gui wont load scene 2 Answers

Calling a function or Object in a level 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