Username Username - 3 months ago 8
C# Question

Debug log is not working for FixedUpdate

Debug.log works fine in

Awake()
function but not in
FixedUpdate()
. Not sure what is wrong

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(SteamVR_TrackedObject))]
public class PickupParent : MonoBehaviour {

SteamVR_TrackedObject trackedObj;

void Awake () {
trackedObj = GetComponent<SteamVR_TrackedObject>();
Debug.Log("debug log is working");
}

// Update is called once per frame
void FixedUpdated () {
SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index);

if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("You are holding down the 'Touch' on the Trigger");
}
}
}

Answer

Looks like you added an extra d to the function name FixedUpdated should be FixedUpdate.

// Update is called once per frame
void FixedUpdated () { // <---------- should be FixedUpdate
    ...

Also the first thing I would have tried is added a Debug.Log call at the start of FixedUpdate to see if the function was being called at all. It not being called would have indicated an issue with the function. If it was called then it would have pointed to the if statement wrapped around the log call.

Comments