Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 caoyuxi · Jul 08, 2015 at 09:52 AM · javascriptnullreferenceexceptiongetcomponent

NullReferenceException: Object reference not set to an instance of an object (when doing js to add value to c#)

here is the js:

 private var mn;
 private var CsharpScript;
 var oscChannel:int;
 
 
 function start() {
    mn = GetComponent("MegaNoise");
 }
 
 function Update () {
     var n = OSCReceiver.messages[oscChannel];
     transform.localScale = Vector3(n+0.3,n+0.3,n+0.3);
      mn.Freq = n+1;
     //Debug.Log(mn.Freq);
 }


i just need to add the value from osc input to the cSharp logic i have here :

 using UnityEngine;
 
 [AddComponentMenu("Modifiers/Noise")]
 public class MegaNoise : MegaModifier
 {
     public float    Scale        = 1.0f;
     public bool        Fractal        = false;
     public float    Freq        = 0.25f;
     public float    Iterations    = 6.0f;
     public bool        Animate        = false;
     public float    Phase        = 0.0f;
     public float    Rough        = 0.0f;
     public Vector3    Strength    = new Vector3(0.0f, 0.0f, 0.0f);
     MegaPerlin        iperlin        = MegaPerlin.Instance;
     float            time        = 0.0f;
     float            scale;
     float            rt;
 
     Vector3 sp = Vector3.zero;
     Vector3 d = Vector3.zero;
 
     public override string ModName() { return "Noise"; }
     public override string GetHelpURL() { return "?page_id=262"; }
 
     public override void Modify(MegaModifiers mc)
     {
         for ( int i = 0; i < verts.Length; i++ )
         {
             Vector3 p = tm.MultiplyPoint3x4(verts[i]);
 
             sp.x = p.x * scale + 0.5f;
             sp.y = p.y * scale + 0.5f;
             sp.z = p.z * scale + 0.5f;
 
             if ( Fractal )
             {
                 d.x = iperlin.fBm1(sp.y, sp.z, time, rt, 2.0f, Iterations);
                 d.y = iperlin.fBm1(sp.x, sp.z, time, rt, 2.0f, Iterations);
                 d.z = iperlin.fBm1(sp.x, sp.y, time, rt, 2.0f, Iterations);
             }
             else
             {
                 d.x = iperlin.Noise(sp.y, sp.z, time);
                 d.y = iperlin.Noise(sp.x, sp.z, time);
                 d.z = iperlin.Noise(sp.x, sp.y, time);
             }
 
             p.x += d.x * Strength.x;
             p.y += d.y * Strength.y;
             p.z += d.z * Strength.z;
 
             sverts[i] = invtm.MultiplyPoint3x4(p);
         }
     }
 
     public override void ModStart(MegaModifiers mc)
     {
     }
 
     public override Vector3 Map(int i, Vector3 p)
     {
         p = tm.MultiplyPoint3x4(p);
 
         float spx = p.x * scale + 0.5f;
         float spy = p.y * scale + 0.5f;
         float spz = p.z * scale + 0.5f;
 
         float dx,dy,dz;
 
         if ( Fractal )
         {
             dx = iperlin.fBm1(spy, spz, time, rt, 2.0f, Iterations);
             dy = iperlin.fBm1(spx, spz, time, rt, 2.0f, Iterations);
             dz = iperlin.fBm1(spx, spy, time, rt, 2.0f, Iterations);
         }
         else
         {
             dx = iperlin.Noise(spy, spz, time);
             dy = iperlin.Noise(spx, spz, time);
             dz = iperlin.Noise(spx, spy, time);
         }
 
         p.x += dx * Strength.x;
         p.y += dy * Strength.y;
         p.z += dz * Strength.z;
 
         return invtm.MultiplyPoint3x4(p);
     }
 
     //public override bool ModLateUpdate(Modifiers mc)
     public override bool ModLateUpdate(MegaModContext mc)
     {
         if ( Animate )
             Phase += Time.deltaTime * Freq;
         time = Phase;
 
         return Prepare(mc);
     }
 
     public override bool Prepare(MegaModContext mc)
     {
         // Need this in a GetDeformer type method, then drawgizmo can be common
         if ( Scale == 0.0f )
             scale = 0.000001f;
         else
             scale = 1.0f / Scale;
 
         rt = 1.0f - Rough;
 
         return true;
     }
 }


and then i got this wired error:

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) ScaleObject.Update () (at Assets/Scripts/ScaleObject.js:13)

the c# file name is MegaNoise.cs and it works with the string "MegaNoise" over another project , but in here it doesn't wondering why!? any one please help!

Comment
Add comment
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

1 Reply

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

Answer by Graham-Dunnett · Jul 08, 2015 at 09:55 AM

When you do GetComponent() it's 100% important that you check the return value. If you do:

 function start() {
     mn = GetComponent("MegaNoise");
     Debug.Log(mn);
  }

then you'll learn something important. (Which to save you the time, is that this function won't be executed. Because its function name is incorrect. Lower-case 's' is your error.)

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 caoyuxi · Jul 09, 2015 at 12:01 AM 0
Share

oh man i am soooooooo stupid ! sorry for bother!

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

2 People are following this question.

avatar image avatar image

Related Questions

GetComponent: Easy help 1 Answer

Xml save/load script gives null reference exception in javascript 0 Answers

NullReferenceException when setting Component as Variable, but no bugs 1 Answer

Why do I keep on getting warning NullReferenceException: Object reference not set to an instance of an object Buttons.Update () 1 Answer

access a script generically? 2 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