Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Shadex · Aug 24, 2016 at 09:18 PM · scripting problemscriptingbasicserrormessage

Some basic Scripting Troubles in C# null reference

I have a bool called "WeaponTrail" on my animator which is on the current game object. I am using the XWeaponTrail asset, and am trying to turn the weapon trail off and on for each melee swing (each attack animation state). The sword has the weapon trail attached to it. The sword is attached to the model, which is all on the same game object like normal. I am recieving a null reference exception with the following code. I'm pretty new in coding, any help would be appreciated.

 using UnityEngine;
 using System.Collections;
 using Xft;
 
 public class SwordTrailSwitch : MonoBehaviour {
     XWeaponTrail xwep;
     Animator anime;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         Swordbool ();
     }
 
 //CGP turn on and off weapon trail CGP
 void Swordbool()
     {
         if (anime.GetBool ("WeaponTrail") == true) {
             xwep.Activate ();
         } 
         if(anime.GetBool("WeaponTrail") == false) {
             xwep.Deactivate ();
         }
 
 
     }
 }
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
0
Best Answer

Answer by Monkiman300 · Aug 25, 2016 at 02:00 AM

Are you trying to activate the sword trail as a game object? If that is the case you need xwep.SetActive(true) and xwep.SetActive(false) respectively. Hope this helped, if not let me know and put the error message in here too, it helps understand the issue for us. :)

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 Shadex · Aug 25, 2016 at 05:28 AM 0
Share

Thank you for taking the time to reply. I'll try to include all the information i can.

I am currently using a system that equips weapons (game objects) on a handler. To use the weapon trail system, you are instructed to attach the prefab to the weapon, and add a start and end point. It also has API instructions which i'll include below. $$anonymous$$y thought was to make a bool that turned true at the beginning of a state and false at the end of a state, and to attach that to each animation state in the $$anonymous$$ecanime State $$anonymous$$achine. Then add a script to the weapon that would use the Activate() if the Bool (WeaponTrail) was true and Deactivate() if the Bool (WeaponTrail) was false. I did this because i won't know what weapon i'll have equiped, and only want to activate the weapon the character is holding. The Bool flipping script is working fine, the SwordTrailSwitch script (the one i posted about) is not though. The SwordTrailSwitch script is attached and is a child of the weapon (which is a game object)

This is the API instructions

 API:
 Activate(): Activate trail
 Deactivate(): Stop trail immediately
 StopSmoothly(float fadeTime): Stop trail smoothly.
 *NOTE YOU NEED TO I$$anonymous$$PORT THE NA$$anonymous$$E SPACE, for example, using Xft; in C#*
 

Here is the Error $$anonymous$$essage i am getting....

 NullReferenceException: Object reference not set to an instance of an object
 SwordTrailSwitch.Swordbool () (at Assets/XWeaponTrail/Scripts/SwordTrailSwitch.cs:21)
 SwordTrailSwitch.Update () (at Assets/XWeaponTrail/Scripts/SwordTrailSwitch.cs:15)

Any help would be appreciated!

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

80 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Accessing script from another object 1 Answer

Performance peaks in ScriptRunBehaviourUpdate 1 Answer

Variable from another script isn´t updating 3 Answers

Performance of event vs static method call 0 Answers

How can I temporary increase the size of an object? 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