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
0
Question by hexagonius · Nov 05, 2016 at 12:23 PM · monobehaviourstartstopcalls

Start() is called on Play and on Stop

I have a script attached to a gameObject. Whenever I press play it Start() function gets called, but when pressing play again to stop play mode, it's called again. I use a custom inspector and a custom property drawer on it and one of its fields. The call stack just shows Start() being called by the engine and not any manual call from any script.

Is this common behaviour in some way, because I don't get it.

Comment
Add comment · Show 5
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 tanoshimi · Nov 05, 2016 at 12:59 PM 0
Share

It's certainly not intended behaviour, and can't say I've ever seen it before. Bit hard to diagnose further without seeing your code.

avatar image hexagonius tanoshimi · Nov 05, 2016 at 02:15 PM 0
Share

Ok, that's basically the code. It must have something to do with deriving from the UI.Text component, but I can't see how:

 using UnityEngine.UI;
 using UnityEngine;
 using UnityEditor;
 
 [CanEdit$$anonymous$$ultipleObjects]
 public class TestText : Text {
 
 //    // Use this for initialization
     void Start () {
         Debug.Log ("Start called");
     }
 }
avatar image iAmAwsum hexagonius · Nov 05, 2016 at 02:58 PM 0
Share

Does it even matter if it's called on stopping? It's not normal but hey, you're stopping the program anyways, aren't you?

Show more comments
avatar image vulgerstal · Nov 05, 2016 at 10:38 PM 0
Share
 using UnityEngine.UI;
 using UnityEngine;
 using UnityEditor;
 
 [CanEdit$$anonymous$$ultipleObjects]
 public class TestText : Text
 {
 
     //    // Use this for initialization
     void Start()
     {
         if (Application.isPlaying) Debug.Log("Start called");
     }
 }

1 Reply

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

Answer by Bunny83 · Nov 05, 2016 at 06:07 PM

This makes no sense. "CanEditMultipleObjects" is an editor attribute an is only used on editor classes. Specifically on custom inspectors. The "UI.Text" class is a component and as such a runtime class.

Why do you actually want to derive your class from Text? In most cases you don't want to do that. You usually write component behaviour scripts which use UI components.

edit

btw: The reason why Start is called when you enter playmode and when you leave it is the ExecuteInEditMode attribute which is atttached to one of the base classes of Text. Specifically to the "Graphic" class. The hierarchy is:

 Text -> MaskableGraphic -> Graphic -> UIBehaviour -> MonoBehaviour -> Behaviour -> Component
                              /|\
                               |
                    This has [ExecuteInEditMode]

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 hexagonius · Nov 06, 2016 at 10:06 AM 0
Share

For some reason I couldn't Reply to your comment so I converted it to an answer. yes, the CanEdit$$anonymous$$ultipleObjects was a mistake while writing that from scratch, I use it on the customeditor.
I wanted to derive from Text, because I need all the functionality except for access to the underlying m_Text variable.

avatar image Bunny83 hexagonius · Nov 29, 2016 at 05:47 AM 0
Share

I've added an explanation for your additional "Start" call.

avatar image hexagonius Bunny83 · Nov 29, 2016 at 08:16 PM 0
Share

uh nice, thanks, i haven't thought of that.

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

60 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

Related Questions

Automatically playing animations 1 Answer

Component's Start/Awake methods not being called 2 Answers

Update and Awake not being called. 1 Answer

Timer that stops at the end of the game 3 Answers

Starting a new animation, after stopping another. Without transitions. 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