Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

The UNKNOWN_OBJECT_TYPE has been declared as [ReadOnly], but you are writing to it.

Discussion in 'AI & Navigation Previews' started by santadiego, Sep 15, 2020.

  1. santadiego

    santadiego

    Joined:
    Aug 31, 2014
    Posts:
    27
    SetTraitOnObjectAtIndex gives me a readonly error. what am I doing wrong?

    public IEnumerator Sleep(GameObject bedObject)
    {
    stateData = (StateData)m_Controller.CurrentStateData;
    var traitBasedObjects = new NativeList<int>(4, Allocator.TempJob);

    foreach (var needObjectIndex in stateData.GetTraitBasedObjectIndices(traitBasedObjects, new ComponentType[] { typeof(Need) }))
    {
    var need = stateData.GetTraitOnObjectAtIndex<Need>(needObjectIndex);
    if (need.NeedType == NeedType.Fatigue)
    {
    need.Urgency = 0;
    stateData.SetTraitOnObjectAtIndex(need, needObjectIndex);
    // alternatively SetValue works but is it the same?

    //m_NeedTraitData.SetValue(Need.FieldUrgency, need.Urgency);

    yield return null;
    }
    }
    traitBasedObjects.Dispose();
    yield return null;
    }
     
    Last edited: Sep 19, 2020