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

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.

Related

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

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.

Unity: Guidelines to add script to Prefab

I am new to Unity and I'd like to know what's the best way to add a script to a Prefab.
I currently see two ways of doing so:
1) Use the Unity interface to add it to an existing prefab
2) Use the AddComponent following the code which instantiates the prefab
I try using the 2) everywhere as I am using git to source control my code and I think conflicts may be easier to resolve inside code (compare to inside .prefab files by instance). But I may be wrong.
Is there any unity good practice regarding this ?
That's indeed the only two ways to add a component to a GameObject.
The primary way you are expected to add components to GameObjects is the Unity interface. Being able to setup logic and data through the interface rather than code is one of the big benefits of using such a game engine. It gives you flexibility and it smooths the process for quite a number of operations.
AddComponent use leans more toward adding a component to change the behavior of an existing GameObject or to create a GameObject from scratch, both at runtime. Most people usually don't make an use of it.
Git handles .prefab merging just fine. These are basically just text files with tags and structure so that it can be interpreted by the engine and be readable for an user (think of XML files).

Prefab in Unity and HoloLens falling below the spatial mapping

I'm working in a Unity application with HoloLens, where I place different prefabs across a room and I use TapToPlace to put it on a surface using SpatialMapping. I works great with some fbx models that I had, but then I received some models that I got in .max format, which I converted to FBX using 3DS Mask, they look good, but the exact setup as the other models, whenever I tap them, they are place halfway below the surface.
I've noticed that the working prefabs puts the cursor right at the bottom when in placing mode, while the "broken" ones put the cursor in the middle. Here is an example of how it looks in Unity:
Working:
Not working:
What is that circle there? it looks like the cursor, because everytime that I tap the object, the cursor is placed exactly there for each prefab, but for the ones in the center, half of the model shows below the surface, somehow it looks like it's related; is there a way to move that to the bottom as the working one looks like? if not, is there something that I need to do in 3DS max when exporting these new models to FBX? both models are using box collider, TwoHandManipulatable and TapToPlace.
Thank you, I appreciate the help.
The issue is on the axisof the model -- the pivot point of the model is not at the bottom of the model.
If at all possible it is recommended that you fix the model in your 3D modelling application, If this is not possible, you can fix it in Unity by adding an extra parent transform, more information please see:
https://answers.unity.com/questions/62675/redefine-axis-of-an-object.html
https://answers.unity.com/questions/357698/can-we-change-the-pivot-points-of-any-gameobject.html

Directly Controlling an .fbx MakeHuman Avatar in Unity With a Script

I imported a character from MakeHuman into Unity as .fbx file.
Now I am trying to controll the characters parts/skeleton, e.g. the head rotation (see picture below for full skeleton structure), directly with a script, but I am pretty new to Unity. Maybe someone has any tips for me on how to acces the parts of the skeleton.
My guess is to use GetComponent() to access every component one by one, but what is their type? And is there maybe a smoother way which keeps the tree structure?
If you imported the rig of the character as humanoid and set all bones in the import tap, you could try to get those propertys out of the animator. He should now which gameobject is which bone, case you mapped it for him.

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.