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 Chuckler · Oct 22, 2013 at 07:52 AM · lightcomponentintensityattached

Light intensity null reference

Hello, I added a light component to a muzzle flash and in the script i added an intensity modifier. It actually works great and looks nice, not being on all the time and it only appears with the muzzle flash, but i am getting a null reference still, i am not sure why...i tried adding a point light instead to the parent objects but that dint kill the call for null...so i am thinking its a small variance in the specifics of the code at the light intensity call...Can anyone help me see whats up here please?hmmm The code is in the late update

 function LateUpdate() {
     if (muzzleFlash) { // We shot this frame, enable the muzzle flash
         if (m_LastFrameShot == Time.frameCount) {
             muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 90, Vector3.forward);
             muzzleFlash.enabled = true;
             //lightGameObject.AddComponent(Light);
             muzzleFlash.light.intensity = 3;
         } else { // no shot, disable the muzzle flash
             muzzleFlash.enabled = false;
             enabled = false;
             muzzleFlash.light.intensity = 0;
 if (bulletsLeft == 0){
         Reload();}
         }
 }
 }
Comment
Add comment · Show 9
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 mattssonon · Oct 22, 2013 at 09:08 AM 0
Share

Where do you get the null reference exception?

avatar image yogee · Oct 22, 2013 at 09:12 AM 0
Share

assign muzzleFlash on Start()

avatar image mattssonon · Oct 22, 2013 at 09:13 AM 0
Share

So nowhere in the code above?

avatar image Chuckler · Oct 22, 2013 at 09:29 AM 0
Share

here is the error message...

$$anonymous$$issingComponentException: There is no 'Light' attached to the "muzzleFlash" game object, but a script is trying to access it. You probably need to add a Light to the game object "muzzleFlash". Or your script needs to check if the component is attached before using it. at (wrapper managed-to-native) UnityEngine.Light:set_intensity (single)

at Weapon_Fire.LateUpdate () [0x00079] in C:\Documending\2Big4Film--3D\Unity3D\GUN_RANGE\Assets\SCRIPTS\WEAPON SCRIPTS\Weapon_Fire.js:140

(Filename: Assets/SCRIPTS/WEAPON SCRIPTS/Weapon_Fire.js Line: 140)

but there is a light attached but via component

avatar image yogee · Oct 22, 2013 at 09:35 AM 1
Share

use muzzleFlash.GetComponent("light name").intensity=3; or place full code

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by yogee · Oct 22, 2013 at 09:48 AM

 function Start () {
     // Make a game object
     var muzzleFlash: GameObject = new GameObject("The Light");
     // Add the light component
     muzzleFlash.AddComponent(Light);      
     muzzleFlash.transform.position = Vector3(0, 5, 0);
 }

 function LateUpdate() {
     if (muzzleFlash) { // We shot this frame, enable the muzzle flash
         if (m_LastFrameShot == Time.frameCount) {
             muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 90, Vector3.forward);
             muzzleFlash.enabled = true;
             muzzleFlash.light.intensity = 3.0;
         } else { // no shot, disable the muzzle flash
             muzzleFlash.enabled = false;
             enabled = false;
             muzzleFlash.light.intensity = 0;
             if (bulletsLeft == 0) {
                 Reload();
             }
         }
     }
 }
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 yogee · Oct 22, 2013 at 10:07 AM 0
Share

In line 6: not lightGameObject it is muzzleFlash ok, try this

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

15 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

Related Questions

Incorrect Intensity value of Light component loaded from Assetbundles 0 Answers

Light Draining Script 1 Answer

[CLOSED] Change intensity of a light with script (which isn´t attached to the light object) 1 Answer

Light intensity with mouse scrollwheel 1 Answer

How to change the intensity to go down over time and to go up after colliding with an object. 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