What is Mono Behaviour? - unity3d

I'm getting this message multiple times when I try to run my game:
The referenced script on this Behaviour is missing
For some reason, all my prefabs are missing a script that dictates something called their 'Mono Behaviour':
What is the Mono Behaviour component, and what does it do?
How can I fix this error? I can click the little target circle to bring up all my scripts, but that just gives me all of the scripts that I've written:
So I don't really know how to replace my missing Mono Behaviour script... Maybe if I knew what it was I could have a clue how to fix it.
I probably moved something. But how can I select the Mono Behaviour script (whatever it is) if the target just shows me my scripts?
Update
I've moved some assets in the project window, but not via the OS (Finder/Explorer) so why is this happening?
Also I am told that Mono Behaviour is a script I've applied...
Don't really get this...isn't the script component a reference to a script?

This happens when you have a script attached to a component, but then the script has been deleted (or its reference has lost in another way, such as the meta file being modified).
If you don't know which script used to be there, just delete those Mono Behaviour components.

MonoBehaviour is the Base Class of all scripts that you want to attach to a GameObject. I am not sure how you managed to create a MonoBehaviour Component with a script missing. What you normally do is write your script and then just drag it from the project view onto the GameObject you want it attached to.

Related

Unity Console not showing result and Object disappears on running

Hi I installed unity hub and added editor ''Unity 2021.1.7f1''.
Now i wrote a simple script in Visual studio Code (VSC shows no error in it), the script is to just write something in the Console, here it isscreenshot is here
I attached the script to an empty objecthere is screenshot
Now on running the console shows nothinghere is screenshot
Why is this happening?
Now i created a 2D square object and added a script to it that i copied from the tutorial i was learning from, VSC shows no error in it as well. Here it ishere is screenshot
I attached this script to the squarehere is screenshot
When i press the run the square disappears from the assets.here is screenshot
I am new so please forgive if i made some technical error. I need help with these two problems. Any help would be appreciated.
The first issue is caused by a typo in your script, you typed start() instead of Start() (Notice the capital S, Unity Event functions are case sensitive.)
For the second issue, it looks you you added the square object while in play mode which doesn't persist changes. You need to make sure you only make changes in Edit mode if you want them to be persisted.

Make sure that there are no compile errors and that the file name and class name match

I keep getting the same error over and over no matter what I do.
"Can't add script component 'PlayerMove' because the script class
cannot be found. Make sure that there are no compile errors and that
the file name and class name match".
I am very sorry that this is very long, but this is the extent of what I have been trying to do to resolve this problem, so please be patient.
I have been working on this 2D project for three weeks. It was working fine until 3 days ago. So far, I had only created the environment and added characters who were doing nothing. There is music and effects. All of these is (still) working fine.
Then I added a script to make my character move. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour {
public float moveSpeed;
public Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
rb.velocity = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, rb.velocity.y, rb.velocity.z);
}
}
I was so happy, my character was moving!! There were no errors! It was all fine. It worked like that for two more days after adding the script. I'm saying this to emphasize that Unity did not crash because of the script.
Unity crashed, this happened on Monday. Even though I did not lose my project files, and restarting Unity did not work, I had to uninstall and reinstall Unity. My version was 2019.4.1f1 before and after as well, been working on same version, since I don't want to get stuck with upgrade issues.
When I reinstalled Unity and reopened my project, unfortunately, Cinemachine and ProBuilder were both gone. This is another problem I have been facing since the start. But that should be another topic.
PART 1
After a lot of work, I gave up and decided to create a new project. Following are the steps I took:
I created a new project
installed CM, PB,
went and imported my project.
The script was not working so I reimported it.
PART 2
It still did not work, so I created a new script- with a different name- by using the method of right clicking in Assets and creating a script.
Then I just copied my THREE LINES OF CODE - literally as you can see above - and tried to add it to my character. Still not adding. It wants to know if the class name and file name are same - which they are of course - no matter how many files I create, in whatever method, I make sure the class name and file name are same. And the class does inherit from Monobehavior. Plz refer to error message in start.
PART 3
I then created another script file. I deleted the previous script, made sure there were no other scripts with similar names, then went to the PLAYER and created a file from the Add Component menu in the Inspector. I double clicked the file from there and then added the code. And after I had saved it in VS 2019, it's an invalid file in the Inspector in Unity.
I have tried doing this with several file name changes. And I have tried to import the script file from another folder. I keep getting the same error over and over again. Just now I finished reimporting all process as well. I even uninstalled VS 2017, and installed all latest .Net SDK Frameworks.
I'll be grateful to anyone who can help.
I also added this question to the Unity forums a week ago (I was getting same error message), and was successful in resolving it, but now that solution is not working.
Remember that I have created absolutely no other scripts. The only scripts present in my project would be the ones attached already to the assets, and there is no asset in my project that requires a movement from input, or can be called a "player character" game object.
Oh, and I also tried to re-drag (?) the Prefab of my Player asset from the main folder over to the scene view. I even just now reimported the whole thing - Reimport all.
I have been trying to shorten the question over and over, but the steps I took to resolve this issue were so many that I could not manage it.
However, good news is that I did finally resolve the issue.
Of all the things that could be expected, this is what worked: I went and deleted all "SmoothMoves" folders from my assets. I have no idea why that helped, I don't know the connection.
Please read this question I posted on Unity Answers - anyone with similar issues - as proof that I don't know what effect SmoothMoves files and folders had on my project and I don't know what effect removing it will have. (Yes, I know some of my character assets (enemies) use SmoothMoves, but I'm still not sure what was in those folders I deleted).
But my main player characters are both now moving. My script file added to the game object without so much as a blink.
https://answers.unity.com/questions/1753426/smoothmoves-dll-file-problem-can-anyone-please-hel.html
So this problem, make sure the class name and file name are same, an odd issue, can arise from SmoothMoves folders (I still have all character prefabs in the project, I only deleted the specific SM folders ONLY). Be careful.

Buttons broken using new Input System

I've got a problem that is seemingly impossible to debug. My project originally started using 2019.2 and upgraded to 2019.3 without any problems. I then installed the preview package for the new input system.
This "disabled" all the buttons in that they are visible in the editor and during run time but they are impossible to click on or interact with.
To reproduce this issue I tried:
Creating a new empty 2D project
Installing and switching to the new Input System
Importing their demo scene from the package manager
At this point I tried running each scene. All of them worked except "SimpleDemo_UsingActions.unity".
I added a button to the "SimpleDemo_UsingPlayerInput.unity" and added a script to the button. With a function:
public void Button()
{
Debug.Log("Button Pressed");
}
I ran this scene and it worked! I could move around shoot the cubes that is built into the script and I could click on the button and it showed in the log.
For this reason I am stumped. I do not know how to debug this issue.
Can I have some advice? Has anyone had a similar issue or know how I would go about debugging this?
I managed to find the answer. For some reason using the new input system's "InputSystemUIInputModule" breaks all the UI and just does not work.
I fixed it by just deleting my EventSystem and creating a new one in the scene.
Do not. and I repeat. Do Not use the new input system's manager for the event system.
I write answer because it's first result in google.
To get rid of this, select EventSystem in hierarchy, then in inspector you should see warning and button to replace old input system with new.
Unity ver. 2019.4.1
Input System ver. 1.0.0
I'm still currently testing but I manage to get something by duplicating the defaultInputActions.inputactions file from the Packages >> Input System >> InputSystem >> Plugins >> PlayerInput.
I realized that that .inputactions has a UI Action Maps. I added more Action Maps and did some testing, the added action maps works and buttons are somewhat reacting as well.
Just sharing this now so that more developers can test this with me and hopefully find a way to work around this major issue.
Had the same issue. Make sure that the input system package, does not have any devices inside... It worked for me after migrating from the Previous Input System

How does monodevelop summary autocompletion work

In monodevelop, if I declare a variable like so...
public int foo = 1;
Then in the line directly above it, i type ///, it will automatically generate this....
/// <summary>
/// The foo.
/// </summary>
How is this happening? Which files in unity are causing this behaviour? I want to know because I want to modify it to add some other generated code.
How is this happening? Which files in unity are causing this behaviour? I want to know because I want to modify it to add some other generated code.
You won't be able to modify Unity's MonoDevelop that easily. They are actually stuck in some old version (which presumably will make your life even more complicated if you want to change its behaviour) that is years old.
Some people use nowadays Xamarin Studio (instead of Unity's MonoDevelop) or the last version of MonoDevelop, with a Unity plugin. This would be a more reliable way for you to go ahead and change MonoDevelop's documentation-autocompletion behaviour, by looking at its upstream source code, and maybe creating an AddIn yourself for the desired functionality.

AndEngine classes - problems with opening declarations: Source not found

Im working with AndEngine in eclipse (which is a 2d physics/tiling engine)
Everything works fine yet when i try to open declaration to classes I get Source not found
I can Change Attached Source...
but i wouldnt know what to change it too...
is there a way i can download the classes so i can view them on my computer (so far im stuck with googling each class and it slows down my progress immensely)
Is this suppose to be happening?
Can i somehow solve this problem or get my hands on some good documentation.
I fixed the problem by extracting the jar file with the JD GUI program. Then i simply opened the declaration and then clicked change attached source... and pointed it to the file (which is still zipped it doesnt work if you unzip it) Everything works well now :D