• 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
Question by psychomantis92 · Oct 01, 2015 at 06:08 PM · unity 5bugerror messagecacheload level

Load and switching level problem

Greetings,

currently i have two levels:

  • Level 1 is the main menu,with 3 images called "glock","deagle" and "uzi" inside a Canvas,each one with a c$$anonymous$$ld image called "equip_button".

  • Level 2 is a map with enemies and has 3 GameObjects also called "glock","deagle" and "uzi",each one with a c$$anonymous$$ld object called "flash".

So my objective is when i change from Level 2 to Level 1 the "equip_button" color of the images changes depending of the current weapon:

Script on the Level 1

On Start():

 GameObject[] weapons = GameObject.FindGameObjectsWithTag ("weapon");

In the Update():

 foreach (GameObject c$$anonymous$$ld in weapons) {
 if(current_weapon==c$$anonymous$$ld.transform.name)
     c$$anonymous$$ld.transform.FindC$$anonymous$$ld ("equip_button").GetComponent<Image> ().color = new Color (1, 1, 1, 1);
 }

but instead,i get an error of "Object reference not set to an instance of an object" in the line where i do the FindC$$anonymous$$ld("equip_button").

Debugging and using another foreach i saw that the 3 objects saved on the "weapons" var are the objects of the Level 1!!!(becouse they had the "flash" c$$anonymous$$ld instead the "equip_button").So my problem is that the Level 1 script is getting the objects of the Level 2,and that's not possible becouse using the Application.LoadLevel() all GameObjects of the Level 2 should be destroyed...

Take some extra and helpfull info:

  • I'm not using the DontDestroyOnLoad method in any object.

  • I put on the start() of the Level 1 script a Cac$$anonymous$$ng.CleanCache () but didn't work.

  • Closing Unity and opening again solves the problem,so i t$$anonymous$$nk that t$$anonymous$$s is a memory or cache problem.

  • The "glock" "deagle" and "uzi" objects of both levels have the same tag("weapon"),but i'm sure that t$$anonymous$$s is not the problem becouse before getting Unity 5 and using Mecanim all worked perfectly!

Thanks for your attention and sorry for my bad english.

Comment

People who like this

0 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 psychomantis92 · Oct 07, 2015 at 01:20 PM 0
Share

Nobody has a solution for this? :(

avatar image DiegoSLTS · Oct 07, 2015 at 02:28 PM 0
Share

I'd like to help but have no idea what to ask for. Can you share a unity package with just the scenes and the buttons reproducing the bug? Maybe someone sees something else causing this weird behaviour.

avatar image psychomantis92 · Oct 07, 2015 at 04:58 PM 0
Share

The 2 scenes has a lot of objects and prefabs,so the package size would be a nightmare to upload and download.Anyway this happens randomly when i change of scene and restarting the unity editor solves the problem,so i think that it is bug of the editor or a memory/cache problem.You know any command to clear ALL?(specially about tags)

Caching.CleanCache (); didn't work and something is cleaning when i restart Unity to make it work.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Moving file failed (Temp/Backupscenes) when starting Game Mode - every Unity version, every project 1 Answer

Unity 5 just removed all my lightmaps after 7 hours of baking 1 Answer

Unity Asset Prefab Bug ThirdPersonController (left rotating bug / Snapping forward Always) 3 Answers

Raycast not detecting ANY HITS AT ALL when starting inside a collider. 0 Answers

error CS0120: An object reference is required to access non-static member `UnityEngine.Behaviour.enabled' 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