Using Unity components from non-monobehaviour classes

How do I get something like this working?

class MyMonoClass : Monobehaviour
{
    Locomotion loco;
    SomeClass someClass;
   
    Start()
    {
        loco = GetComponent<Locomotion>();
        someClass = new SomeClass(loco);
    }
}

class SomeClass
{
    SomeClass (Locomotion loco)
    {
        // Do stuff with locomotion
    }
}

I get a ‘Object reference not set to an instance of an object’-error when trying to access the Unity class.

I see no reason why that should not work, however considering you get a null reference error it is probably because your GetComponent thingie fail.
Also make sure to include UnityEngine at the top of the SomeClass class. ( I suppose you do though since Locomotion probably wouldn’t be recognized if not, but just thought I’ld say just in case. )

using UnityEngine;
public class MonoClass : MonoBehaviour {
Locomotion loco;
SomeClass someClass;

public void Start(){
     loco = GetComponent< Locomotion >();
    
     if( loco != null ){
          someClass = new SomeClass();
          someClass.DoSomething( loco );
     }
     else {
          Debug.LogError( "No Locomotion component was found!" );
     }
}
}

using UnityEngine;
public class SomeClass {

     public void DoSomething( Locomotion loco ){
          // Do stuff with locomotion
     }
}