0
\$\begingroup\$

Can you please help me figure out why obj.name = resBuilding.name; causes a NullReferenceException?

public static void UpdateList<T>(List<T> list, Dictionary<string, T> dict, string ID, T resBuilding) where T : ResourceBuildings, new()
{
    Debug.Log("Input ID: " + ID);
    T obj = new T()
    {
        ID = resBuilding.ID,
        hourlyIncome = resBuilding.hourlyIncome,
        baseHour = resBuilding.baseHour,
        incomeIncrement = resBuilding.incomeIncrement,
        totalSupply = resBuilding.totalSupply
    };
    obj.name = resBuilding.name;
}

I debugged "resBuilding.name" which works fine. I do not declare a property "name" in any of my scripts as the Object class already has a "name". property.

Inside a separate script I have similar code though not a generic GameManager.selectedLot.name = "Farm"; that executes as expected.

\$\endgroup\$
  • \$\begingroup\$ Can you show other classes as well? \$\endgroup\$ – Saad Anees Jul 11 '18 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.