Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    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