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 CrashTheSniper · Jul 30, 2014 at 01:03 PM · errorbuildvariablesmissing

Build problem, missing variables

(Sorry for my english) I have a scene with 3 mesches. Each mesh has this script:

     using UnityEngine;  
     using System.Collections;
     
     public class Button : MonoBehaviour {
     
         public Shader shader1;
         public Shader shader2;
         public Object levelToLoad;
     
         void Start()
         {
             shader1 = Shader.Find("Diffuse");
             shader2 = Shader.Find("Self-Illumin/Diffuse");
             renderer.material.shader = shader1; //to include the shader Self-Illumin/Diffuse in the build
         }
     
         void Update()
         {
     
         }
     
         void OnMouseOver()
         {
             renderer.material.shader = shader2;
         }
     
         void OnMouseExit()
         {
             renderer.material.shader = shader1;
         }
     
         void OnMouseDown()
         {
             Application.LoadLevel(levelToLoad.name);
         }
 }


I assign the script to each mesh and the scene to load to each script, but when i build and run the progect and i click on a mesh instead of load the assigned scene appear an error on the development console.

This is the error: NullReferenceException: Object reference not set to an istance of an object

How can i fix this error?

error1.png (33.1 kB)
error3.png (192.4 kB)
Comment
Add comment · Show 7
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 $$anonymous$$ · Jul 30, 2014 at 01:06 PM 0
Share

It depends on where that Unassigned Object is in code, try to click on that error in Console and it should take you to the line where you're trying to access that unassigned object and look to Inspector, whether is that object asigned there or from another script.

avatar image meat5000 ♦ · Jul 30, 2014 at 01:09 PM 0
Share

Post the full error including line numbers.

Good attempt at formatting but you pressed the BlockQuote ins$$anonymous$$d of Format (101010) button.

avatar image Arcadewiz · Jul 30, 2014 at 01:10 PM 0
Share

I think this question might be answered here :

Shader Query

avatar image RedDevil · Jul 30, 2014 at 01:14 PM 0
Share

did you atach the levelToLoad object in the inspector?

avatar image Arcadewiz · Jul 30, 2014 at 01:23 PM 0
Share

Probably, your Shader.Find cannot find the mentioned shaders. Did you check the link I posted.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dsada · Jul 30, 2014 at 01:49 PM

In a few words the problem is that the shaders dont get compiled in the build.

When Unity creates your build it compiles everything in the Resources folder but from the Assets folder only those objects are compiled that you have a reference in the compiled scenes or in the Resources folder.

For example if you have a material in the Resources folder that uses the "Self-Illumin/Diffuse" shader, this shader also compiles even if it is not in the Resources folder. Also if you put a scene in the build that has a gameobject that uses a material from the Assets folder and that material uses this shader the shader will be in your build.

But i guess you dont have a reference to the shader and it is not in the Resources folder. It is normal that it is working in the editor because all the resources are available in the editor.

The solution might be that you create materials in the Resources folder and use the needed shaders on them. Or just put the shaders in the folder but honestly I dont know where to find them. Also if you created the materials you dont need to use Shader.Find() then you can just use (Resources.Load("materialName") as Material) and you can assign them to the meshes.

One other note: If your meshes dont use the same material dont use renderer.material because it makes a copy of it. Use renderer.sharedMaterial instead.

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 CrashTheSniper · Jul 30, 2014 at 01:59 PM 0
Share

The shaders work fine because the mesh "PLAY" has the shader self-Illu$$anonymous$$/Diffuse, the other meshes have the shader diffuse, qhen i play the game renderer.material.shader = shader1 set the shader to diffuse because it is set to self-illu$$anonymous$$/diffuse.

The wrong part is that loadToLevel is assigned in the ispector but, it isn't assigned in the build. I'm working to a solution...

avatar image dsada · Jul 30, 2014 at 02:28 PM 0
Share

Oh i see. Is it important that loadToLevel is an Object and not a string?

avatar image dsada · Jul 30, 2014 at 02:29 PM 0
Share

also be sure that you save your scene before the build

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error when build the game 1 Answer

A node in a childnode? 1 Answer

Build Problem - asset is marked as don't save 9 Answers

Distribute terrain in zones 3 Answers

Built game error 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