Animator does not have an AnimatorController - unity3d

I'm very confused, I try to play animation when hitting a certain object, the hit is detected correctly (the attempt debug) and after that I try to play animation that exists on the object (via the Animator)
yet it tells me Animator does not have an AnimatorController and wont play the animation. Clearly there is an AnimatorController, and he is in fact working correctly:
my code:
if (d.name == "furnacedef")
{
Debug.Log("attempt");
Animator b= d.model.gameObject.GetComponent<Animator>();
b.Play("burning");
}

Related

Disable a joystick Unity 3D

edit
After messing with this for a while, what it seems like is that, something was changed in unity. I tried using a bool instead and it works much better. Although I currently have to hold down the gamepad button due to the logic, some progress was made and at least he's going straight out of rolling into running with no problem.
I'm trying to disable the joystick so that after my player does a roll, he will go into an idle animation for a short period and then go back to the blend tree. The blend tree contains idle walk and run animations. At the moment he will roll, transition with "Has Exit Time" into an idle animation (but is still able to slide around if you have the joystick held down) and then transition with "Has Exit Time" to the blend tree.
https://www.youtube.com/watch?v=RVWh-YAQElQ
it's from this tutorial, but I don't know. He never mentions this problem in the video and no one in the comments sections mentions says anything. But basically if you just transition from the roll animation to the blend tree and keep the joystick held down, the animation skips once the roll animation is over. Instead of him just stopping for a second and then allowing the player to move again.
public void OnEnable()
{
if (inputActions == null)
{
inputActions = new PlayerControls();
inputActions.PlayerMovement.Movement.performed += inputActions => movementInput = inputActions.ReadValue<Vector2>();
inputActions.PlayerMovement.Camera.performed += i => cameraInput = i.ReadValue<Vector2>();
if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Idle"))
{
inputActions.PlayerMovement.Movement.performed += inputActions => movementInput = inputActions.ReadValue<Vector2>();
}
}
inputActions.Enable();
}
I've tried disabling the joystick with the code at the bottom, but it just ignores it for some reason.

Unity Hand tracking issue on the quest with UI raycasting

I'm working on a Unity project, trying to test the UI interaction on the Quest II with hand tracking and ray casting.
I've set up a very basic scene with all the default assets (OVRCameraRig, UIHelper) and added just a button to test the UI interaction.
This is what my scene looks like:
The issue I have is, when I run the scene, the Ray is rotated 90 degrees, and it's attached to the wrist for some reason. I made a video here to show what I mean :
https://www.youtube.com/watch?v=5f12yfpugB8
It's still interacting with the UI though.
Then after watching some online tutorials, I commented out these lines in the HandInputSelector.cs, which was attached to the UIHelper:
void SetActiveController(OVRInput.Controller c)
{
/*
Transform t;
if(c == OVRInput.Controller.LTouch)
{
t = m_CameraRig.leftHandAnchor;
}
else
{
t = m_CameraRig.rightHandAnchor;
}
m_InputModule.rayTransform = t;
*/
}
and instead added a 2nd script to the UI helper, with these lines only:
public OVRHand hand;
public OVRInputModule inputModule;
private void Start()
{
inputModule.rayTransform = hand.PointerPose;
}
Now the ray is at least attached to the correct position, but it still doesn't rotate properly with the hand movement. I made another video of it here :
Now the ray is at least attached to the correct position, but it still doesn't rotate properly with the hand movement. I made another video of it here :
https://youtu.be/q3d0eG2LwY0
My Unity version is 2021.3.1f1
Can someone please tell me what I'm doing wrong?

Unity: Trying to load and run an fbx animation

I am trying to load an animation from an fbx file and have it play on a GameObject:
TestObject.AddComponent<Animation>();
animation_handler = TestObject.GetComponent<Animation>();
walking_anim = Resources.Load("fbx_anims/walking_anim_test", typeof(AnimationClip)) as AnimationClip;
if(walking_anim == null)
{
Debug.Log("walking anim not found");
}
walking_anim.legacy = true;
animation_handler.AddClip(walking_anim, "walking");
animation_handler.wrapMode = WrapMode.Loop;
In the game loop, I tried using this:
if (Input.GetKeyDown(KeyCode.W))
{
if (!(animation_handler.IsPlaying("walking")))
{
animation_handler.clip = walking_anim;
animation_handler.Play("walking");
}
}
It doesnt give any errors, yet it doesn't work either. Anything I'm missing?
EDIT: For clarification: The model stays in the default T-Pose, after pressing 'W'. After inserting Debug.Logs at different points, I can confirm that the Play function is getting called only once, after which IsPlaying always returns true. Yet the "playing" animation causes no visual changes in the model (yes, the bone names are the same).
You don't want to use the Animation component, it is an old legacy component that has been replaced by the much improved Animator component. There are a lot of good posts on the Internet on how to use it - no need to repeat it here. The important steps are:
Add the Animator (not Animation) component to the model.
Create an "Animator Controller" in your project and add the clips (like the "walking_anim"). Here you can have a lot of different clips and tell Unity how to interpolate between them by using different parameters.
Add the "Animator Controller" to your "Animator" component.
Add an "avatar" of your model (usually created when the model is imported).
By code alter the parameters of the Animator Controller to tell it which animation clips to play.
It may look like a lot of steps, but it is not so hard and you will quickly have a walking, running, jumping creature on your screen. Good luck!

Why 'Is Kinematics' works different on HoloLens?

Overview
I wanted to have a cube, that I can drag around the scene with the components Collider, Rigidbody and ObjectManipulator. In play mode everything works fine, but running it on the hololens, the cube starts flying around after dragging it a few time.
Steps to reproduce (All components are set via editor, not via code)
Create new project and set it up for AR/HoloLens
Import MRTK 2.4
Create cube with a Box Collider. Set Is Trigger = true
Add Rigidbody to cube. Set Use Gravity = false and Is Kinematic = true
Add Object Manipulator to cube. I have a method getting called after On Manipulation Ended, but don't know if thats important.
Expected behavior
The rigidbody is set to Is Kinematic = true and Use Gravity = false, so that the cube stays still/stops moving after releasing dragging it. This works while trying it inside the unity play mode. But running it on the hololens, the cube behaves like Is Kinematic = false and starts flying around after interacting with it. Sometimes after the second drag and sometimes after the third time drag.
Error
Before updating this post, I didnt noticed the development console in left corner of my hololens. At the beginng of the scene I get the message [Physics.PhysX] BV4 midphase only supported on intel platforms but at that moment everything is fine. As the cube begins to fly around I get the a NullReferenceExeption: Object reference not set to an instance of an object.
I fixed my issue. I know the approximate cause, but I do not fully understand it. The method, getting called after OnManipulationEnded caused that.
I have a list, getting filled and drained by OnTriggerEnter/-Exit (exit looks the same, except add→remove):
private void OnTriggerEnter(Collider other){
if (other.gameObject.layer != 31) return;
_objectsCollidingWith.Add(other.gameObject);}
OnManipulationEnded triggered this method:
private int GetMeshes(List<KeyValuePair<Transform, Mesh>> transMeshes){
foreach (GameObject go in _objectsCollidingWith)
{
transMeshes.Add(new KeyValuePair<Transform, Mesh>(go.transform , go.GetComponent<MeshFilter>().mesh));
}
return transMeshes.Count;}
So I got alot of nullreferences from GetMeshes, because some gameobject in the list _objectsCollidingWith were null. Thats because the mesh is getting updated every once in a while. That caused a lot of nullreferences until the cube just flew away.
I used the whole time the logging provider via the device portal and couldnt see what is causing this errors. But after running the project via holographic emulation I could see in the console where they were coming from.
How did I fixed my problem?
I found this post because I realized that my OnTriggerExit didn't get called and cased having null objects and some spatial meshes with the same name triggered OnTriggerEnter very often. Also I added this line in the foreach loop in GetMeshes because once in a while there is still a null object:
if (go == null)
continue;
PS: Please forgive the strange code formatting, somehow the editor here on so does not allow me to place the brackets somewhere else

Unity. Cant play animation in animator

i'm making a game in 2d and whenever i create an animation sprite, an animator controller is created automatically, i dont know why, i once tried it but i thought it wouldnt be necesary for animations i just want to make in 2d.. so after trying many times to play an animation without the animator (because unity says i have to set the animation legacy, which i dont know where), i gave it a try to play animations in the animator.. i searched through the script reference and wrote the code just like this:
#pragma strict
var velocity : float = 8;
function Update ()
{
var movement = Input.GetAxis("Horizontal") * velocity;
transform.Translate(Vector2.right * movement * Time.deltaTime);
if(Input.anyKey)
Animator.Play("move");
}
the error that unity says is : Assets/PlayerControl.js(12,26): BCE0020: An instance of type 'UnityEngine.Animator' is required to access non static member 'Play'.
so i tried to do this:
function Start ()
{
//var anim = GetComponent("Animator");
}
function Update ()
{
var movement = Input.GetAxis("Horizontal") * velocity;
transform.Translate(Vector2.right * movement * Time.deltaTime);
if(Input.anyKey)
anim.Play("move");
}
and another error occurs: Assets/PlayerControl.js(17,17): BCE0005: Unknown identifier: 'anim'.
i just want to play one simple animation that will just change the sprites. i know how to play animations without the animator.. so please tell me what to do with it.. how to stop unity auto creating animator controller or set the animation legacy, or how to fix this problem with the animator script.
Update:
i removed the code code just to make other stuff while i search solution for this but now it seems that animator is running this animation no matter what.. i made another state on it as idle, but then it goes to the animation i created.. i really dont understand this.
You can check Unity3D Animation mechanism with example http://docs.unity3d.com/Manual/Animator.html
Unity doesn't give us static method for animation play. See above.
http://docs.unity3d.com/ScriptReference/Animator.html
Try to play of animation
GetComponent("Animator").Play("move", -1, 0.0f);
Check the script reference of official site.
http://docs.unity3d.com/ScriptReference/Animator.Play.html