The type arguments for method 'Component.GetComponent<T>()' cannot be inferred from the usage.

I’m taking an Edgenuity course on game design, and I ran into an error. I triple-checked my steps and I still get this error. Here is the code:

using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;

public class Mover : MonoBehaviour
{
    private Rigidbody rb;
    public float speed;
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent();
        rb.velocity = transform.forward * speed;
    }

    // Update is called once per frame
    void Update()
    {
       
    }
}

Line (13,14) is the problem, yet I don’t know what’s wrong with it, because it’s written as Edgenuity wants it to be. Can someone help?

The correct syntax is:rb = GetComponent<Rigidbody>();

1 Like

Thanks, that fixed it.

It seems like the question being asked is why this type parameter is required, as indicated by the line given as part of the question, not what the problem is. I’m curious too, in what way can the usage not be inferred? The variable is declared as a Rigidbody, the type seems obvious to me, why is the compiler saying the type can’t be inferred from the usage?

THanks!