Field "X" is never assigned to and will always have its default

Hi there, as I launch my project in game mode, I am always prompted with “Field “X” is never assigned to and will always have its default value to null”. While it is not a critical message (being yellow) and not preventing the right execution of the game, I have also had that in the previous project.

I suppose I am doing something wrong but can’t figure what. Here a screenshot of my unity and beginning of code.

Thanks in Advance !

1 Like

Hi,

Nothing you’ve done wrong, it’s supposed to do that :slight_smile: As you’ve identified it’s not really a critical issue so you don’t really have to worry about it. The reason you’re getting the error is Unity is saying “Hey, in the code here you never tell me what these variables should be so I might do the wrong thing if you don’t assign them”.

For “rcsThrust” and “mainThrust” you don’t have this problem as you give them values on creation and for “ridgidBody” and “audioSource” you assign these in Start(). That never happens with the particle effects or audioclips. It works fine as you’ve assigned them in the editor which you can do as it’s serialized but unity still treats them like private variables for warnings etc. You can get rid of the warning but making the variables public instead.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms