Text Mesh Pro UGUI Objects disappearing in Play Mode, Unity Version 2019.3.5fl Personal - unity3d

So I have been stuck in this issue for awhile now: I get the error message: "Reference Exception: Object reference not set to an instance of an object" but that's because some of my text mesh pro objects gets deleted by itself!!! Apparently every single time I hit play some of the text mesh pro objects disappear from where it was assigned in the first place..
Code Implementation in the script class:
Example: This is how it look before play mode:
Now this is how thei nspector section looks like while on play mode:
Now once I hit play a few text mesh pro objects just got deleted by itself..
Any idea or feedback please?
Thank you in advance!
Amaury

Alright I see what is Wrong.
In the inspector, you set every Text Mesh Pro Object you need.
But in your script, you are using the function GetComponent on every of the object, which is useless and even buggy since you already declarate them in the inspector.
Remove these lines and it should work :)
EDIT: Also, for your interest, the function GetComponent will only return the first component found ATTACHED to the gameObject. But you don't have TMPText attached to your gameObject and more than that, you don't have MULTIPLE TMPText attached.

Related

Why do my 2D objects not collide in Unity despite that the layers are set correctly?

I have a platform that I need to flip the direction of when it collides with an object. The platform as well as its child objects belong to the layer "FlyingOrPlatform". The object that the platform collides with should belong to the "GameControl" layer. But if i set it to that it doesnt collide with it.
If I set the object that the platform collides with to either the "Player" or "Default" layer. Then it works completely as it should. But I wish to use the "GameControl" layer.
I have tried where I save the scene and the project, as well as restarting the editor.
I dont see what should be wrong with my layer setup. Any suggestions?
In my script for reversing the platform direction there is no layer check, it does check the tag but I ensured that the tag is the same when I switch between the layers. I just use Unity's built in OnTriggerEnter2D lifecycle method. Have tested with OnCollisionEnter2D and OnTriggerStay2D as well, same result.
Here is a link to a video demonstrating the issue, as well as a screenshot of my physics2D settings below. In the video I first show how its supposed to work, and then I switch the object the platform collides with to the GameControl layer, after which it doesnt work.
Video of issue: https://www.youtube.com/watch?v=l-eqYI-K-Ug
Physics2D settings:
From what I can tell this appears to be an issue with the Physics2D matrix in Unity that occurs from time to time. A couple of other people have written similar things on other forums.
Among others this reply had a similar issue:
For lack of better, I found a work-around by using the "Ignore Raycast" layer instead of the "GameControl" layer.
I have reported it as a bug to Unity.
EDIT:
Here is the reply I got from Unity.
"Hi,
We successfully reproduced this issue. It will be possible to follow
the progress on a chosen resolution in our public Issue Tracker once
the report has been processed (this might take up to an hour):
https://issuetracker.unity3d.com/product/unity/issues/guid/1325018
We highly appreciate your contribution. If you have further questions,
please feel free to contact us."

Can't add Orbital script - "The script needs to derive from MonoBehaviour!"

I am developing in Unity 3D for the Microsoft HoloLens 1. I am trying to add the Orbital script from the Mixed Reality Tool Kit to a GameObject, but no matter what I do I keep getting this error message:
"Can't add script behaviour ScreenSpaceMousePointer. The script needs to derive from MonoBehaviour!"
I don't understand why I'm getting this message, since I'm trying to add Orbital, not ScreenSpaceMousePointer. Is there any way to get around this?
EDIT: For further context, I am trying to affix an upright plane with a little map on it to the bottom right of the HoloLens display such that it follows the user wherever they turn their head (much like how a minimap looks in video games).
Orbital inherits from Solver which inherits from MonoBehaviour. So you should be adding it to a GameObject. It's unclear why that error message is appearing without more information.
What version of MRTK/Unity are you using?
Can you create a cube and add orbital via "AddComponent" in inspector?
Can you search for the orbital script in your assets window and drag it onto a simple cube in inspector?
Unfortunately I cannot repo your issue. You can also try looking at the SolverExamples unity scene.
Please, show this script.
Head of it must be like this:
class Orbital: MonoBehavior {
And file name must be Orbital.cs
You may create this file and put inside code you need, but rename class and file to avoid duplicate class name.
Do you have errors in your project? This usually happens for a message you got.

Object Reference seems not set properly(although it was set properly) in Unity

In my Unity project, although I set the object reference to the instance of the object, I still get the error:
NullReferenceException: Object reference not set to an instance of an
object QuestionCode.CountryChange (UnityEngine.GameObject
button_country) (at Assets/scripts/QuestionCode.cs:898)
However, I am sure that there's no problem with object settings because it was working properly before with exactly same settings I have now.
But I discovered a weird property now and suspect if that might be the problem. As you can see from the figures, my main script for the game has a circular shape(I didn't understand why a script had a geometrical shape anyway) and remains outside of the canvas. This situation doesn't make any sense to me at all.
And unfortunately I can't provide my code here since it's too long and I don't think that there's a problem with the script. So what possible solutions do I have here?
These circular shapes form my QuestionCode script:
Here, you can see Canvas and QuestionCode together. Some parts of questioncode remain outside of the canvas and some cover the whole canvas. And also you can see the error in the console.
The 'geometrical shape' you're seeing in the editor is not from the script. It's a component that's been added to the object somehow. Turn everything off on the gameobject until it goes away, and there's your culprit. That being said, the component being added to your gameobject is not going to cause that error. The error you're getting is definitely from your script, which is most likely because a variable has not been set in the editor. From the pictures you provided, I am unable to see but I'm willing to bet that it's a public variable that has not been set.
I have no idea about what did you do in your code. This error message is so basic that no one can guess the reason. You should check your code following this hit:
An Unity object can NOT work properly with some C# operator like ?.. because an object shows invalid in Inspector windows is still not null in C# code. In this case, it triggers the error message come out.

Unity3d and vuforia detecting if target appears

I am new here so I want to ask my first question.
I am using unity3d and vuforia for augmented reality.
I already set up AR camera on my scene and target image and object and works perfectly.
I am trying to play a sound when my 3d model appears on stage but without any luck.
So far I tried to follow this tutorial: https://www.youtube.com/watch?v=4u177CpPbp8 but in the line public class PlaySoundOnImageTarget : MonoBehaviour, ITrackableEventHandler comes with an error on ITrackableEventHandler.
It's red colored and when I am moving my mouse on this it says "error CS0103: the name ITrackableEventHandler does not exist in the current context".
I tried to write the full code but a lot of lines come with almost the same errors.
Also, I tried this one: [https://developer.vuforia.com/forum/faq/unity-how-can-i-play-audio-when-targets-get-detected]
Any help, please?
I am using unity3d 5.4.2f2.
You will need to include Vuforia before you can use it.
You can do so by placing Using Vuforia; at the top of your screen
Next time you might also want to read through the pages of Vuforia as they already solve this and a lot of other very basic errors you might walk into in the near future.

UnassignedReferenceException: Event after assigning?

I'm an experienced programmer learning Unity for the first time. I know this is the most basic and common error for the newbies. I think I have got it right but it still produces this error. What am I doing wrong?
UnassignedReferenceException: The variable player of 'GameManager' has not been assigned. You probably need to assign the player variable of the GameManager script in the inspector.
I think the following screenshot provides everything needed.
you have to assign Game Asset in the hierarchy panel to the game object which has GameManager.cs Script Component
I too am new to Unity and had a similar problem, but after thinking about what was going on I came to the conclusion that the error message was misleading me a bit. When it tried to be helpful by suggesting "You probably need to assign the player variable of the GameManager script in the inspector" I went straight to the script and set it but the error persisted.
It was then that I realised that I didn't have an object in the Hierarchy panal which had my script attached. What I was doing was instantiating an object (my 'player' prefab) at runtime and it was the prefab that had the script attached. Of course, my script might be added to any number of objects and each object will have its own variables, so each object needs to have its own instances of its variables set. If you wanted the same value to be set in all instances you probably make your variable static but it won't then appear in the inspector. So, setting the variable in the Script component of my prefab fixed it for me.
I think that's enough waffle for one day - hope it helps somebody! :)