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 /
avatar image
0
Question by MSachs · Sep 17, 2018 at 06:06 AM · errorerror messagevisual studiowarning

Visual Studio error for referenced scripts

Hi,

I switched over to Visual Studio recently and I always get an error whenever I have a public class referenced in another script. The error/warning message is:

Warning CS0649: Field 'Script.referencedScript' is never assigned to, and will always have its default value null (CS0649) (Assembly-CSharp).

even though in the script there are functions called from the referenced script. Actually everything works just fine when running the game but I am still curious what these warnigns mean exactly and how I can get rid of them.

Thanks in advance :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by JVene · Sep 17, 2018 at 01:36 PM

Without a code example of the compiler warning we can only answer in generalities, but this warning is part of what Visual Studio brings to the development toolset (and there are lots of ways to get this feature).


What you're seeing is the result of some code checking / analysis, and some tools go much deeper into studying the code we write to make suggestions and observations known to create bugs that aren't obvious when we write. It isn't always a good idea to ignore warnings, professional developers work to write code that passes all inspection from analysis tools, but here I speak of development outside of Unity in all manner of applications, many of which are critical. If you're studying, consider the warnings of this type as an introduction into the kinds of things known by professionals and academics to be noteworthy, historically the source of bugs, but for you they may occasionally be ignored until you have a problem (crashes, errors, etc.). Sometimes these warnings give you some indication of why a crash has happened.


It would seem the compiler things there is a member variable that starts uninitialized, where the default for all class and struct types is null. If you access such a variable it would create a crash (null exception), but if you know you do initialize before accessing the value, or you know that you test for null before trying to use it, you're generally covered.


As you become more advanced, these warnings should reduce in volume. They're worth understanding and avoiding, and as you select options to analyze code or increase the warning level (an option to the compiler), the compiler starts to list a lot of warnings you may never have seen before. Full code analysis can even read to be insulting if you didn't realize it was generated by a computer program ;)

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 MSachs · Sep 21, 2018 at 08:03 AM 0
Share

Thanks for this in depth answer!

To make it more clear: I basically have two scripts. ScriptA and ScriptB. ScriptA has some type of function let's say functionA.

In ScriptB I have a reference to ScriptA and for example in ScriptB I have an On$$anonymous$$ouseDown() function in which I am also calling functionA from ScriptA. In code it would look something like this.

 using UnityEngine;
 
 public class ScriptB : $$anonymous$$onoBehaviour
 {
     [SerializeField]
     ScriptA SA;
 
     void On$$anonymous$$ouseDown()
     {
           SA.functionA();
     }
 }

The error message of the original post is displayed next to the "ScriptA SA;" part. Like I said the script doesn't seem to be affected by this at all since functionA is called without any problems but I really would like to know why this warning appears and how to get rid of it.

avatar image
0

Answer by dan_wipf · Sep 17, 2018 at 01:12 PM

Have you downloaded any extions for the visual studio? like c# completer. sometimes a restart helps aswell.

but the error means that you have properties which are never used i guess!

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

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

124 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 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

Visual Studio 2019 stopped working with Unity 2019.1.10f1 0 Answers

Error : GPGSUpgrader.cs(194,80): warning CS0162: Unreachable code detected 0 Answers

Visual Studio Code doesn't work for with unity 2 Answers

Is there any way to ignore all errors in a file? 1 Answer

Visual studio says no issues found even though there are errors. 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