Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 InfinityX · Jul 17, 2013 at 08:37 PM · c#rendererinvisiblereloadrestart

Renderer on object disabled after level reload

Hi

I'm sorry for a noob question, but I'm fighting with it for some time already. I've got a simple code on one object:

 // Use this for initialization
     void Start()
     {
         gameObject.SetActive(true);
         gameObject.renderer.enabled=true;
     }
     
     void Awake()
     {
         renderer.enabled=true;
         gameObject.SetActive(true);
     }
     
     // Update is called once per frame
     void Update () 
     {
         if (Input.GetMouseButtonDown(0))
     {
             ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if(Physics.Raycast(ray,out hit))
             {
                 if  (collider.name == "start")
                 {
                     starting = true;
                 }
             }
         }
         else if (Input.GetMouseButtonUp(0))
         {
             starting = false;
         }
         
         if (discount.animEnd)
             //gameObject.SetActive (false);
             renderer.enabled=false;
             //Destroy (gameObject);
     }

After level reload using "Application.LoadLevel(Application.loadedLevelName);", the object is not visible. Also in Inspector the renderer on the object is disabled.

Thanks in advance

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 screenname_taken · Jun 30, 2014 at 06:18 PM 0
Share

why are you doing the same thing in both awake and start?

avatar image jjplay175 · Aug 24, 2014 at 12:38 PM 0
Share

@Screenname Just a question, is awake supposed to be before start or does it not matter at all?

@Infinity Just a note that I think awake loads before start does just for all your other scripts in case you didn't know

avatar image felixpk · Jun 25, 2015 at 01:57 PM 0
Share

Awake() is called before Start() and also is executed even though the gameObject is not active. If you reload the scene all scripts are executed from the beginning like when you press the play button. So my guess would be that another script is disabling your gameObject. Do you have any other scripts?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by spraw · Jun 30, 2014 at 05:34 PM

     void Awake()
     {
     renderer.enabled = true;
     }
     
     void OnLevelWasLoaded()
     {
     renderer.enabled = true;
     }

Although I'm not sure if you need to make the class persistent, why are you completely reloading the level anyway?

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Separate script from reload? 0 Answers

How do I remove the automatic restart function from the Survival Shooter tutorial series?, 1 Answer

How to change a value in custom shader through script, C# 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