I have been working with the Unity Robotics Hub, successfully implementing a pick-and-place tutorial with the Niryo One robot. Moving forward, I attempted to apply the same principles to a UR3 robot. The UR3 was imported into Unity using the URDF importer, and I followed the same setup steps as the tutorial.
However, I'm encountering a NullReferenceException
when trying to run my scene. The console points to this line in the Start()
method of my V_1_SourceDestinationPublisher
script:
csharp
m_JointArticulationBodies[i] = m_NiryoOne.transform.Find(linkName).GetComponent<UrdfJointRevolute>();
Here's a snippet of the script where the exception occurs:
// ... [previous code]
void Start()
{
// Get ROS connection static instance
m_Ros = ROSConnection.GetOrCreateInstance();
m_Ros.RegisterPublisher<NiryoMoveitJointsMsg>(m_TopicName);
m_JointArticulationBodies = new UrdfJointRevolute[k_NumRobotJoints];
var linkName = string.Empty;
for (var i = 0; i < k_NumRobotJoints; i++)
{
linkName += LinkNames[i];
m_JointArticulationBodies[i] = m_NiryoOne.transform.Find(linkName).GetComponent<UrdfJointRevolute>();
}
}
// ... [rest of the code]
I have already updated the LinkNames array with the names corresponding to the UR3 robot's links. The ROS connection is established without issues, but it seems like Unity can't find the components it's supposed to reference.
Could someone help me understand what's causing this NullReferenceException and how to fix it?
Here's the GitHub repository for the Unity Robotics Hub I'm using: Unity Robotics Hub.
Any suggestions or solutions would be greatly appreciated. Thank you!
If, as you said, the null exception error points to this line
m_JointArticulationBodies[i] = m_NiryoOne.transform.Find(linkName).GetComponent<UrdfJointRevolute>();
, and you're sure thelinkName
s are correct, then the other likely culprit would be m_NiryoOne. It may be null, and you may want to check how you're referencing it.The surest way to find out is to use a debugger and breakpoint on that line.