How do I change a field with hook_node_presave()?
A bit outdated but still a great resource:

http://wizzlern.nl/drupal/drupal-8-entity-cheat-sheet

Also the documentation on drupal.org: https://www.drupal.org/node/1795854

In short, fields are lists of objects that use property and array access magic methods to simplify reading and writing values to them:

// Set a value, the field class will decide what to do with it, usually write to the primary property...
$entity-&gt;field_fieldname = importantfunction();

// The default property is often called value, but for reference fields, it is target_id, text fields also have a format for example
$entity-&gt;field_fieldname-&gt;format = 'full_html';

// By default, you access delta 0, you can also set other deltas.
$entity-&gt;field_fieldname[1] = importantfunction();

// You can also append a new item, without hardcoding the delta.
$entity-&gt;field_fieldname-&gt;appendItem(importantfunction());

// Note that when accessing fields, you must always specify the property:
print $entity-&gt;field_fieldname-&gt;value;
print $entity-&gt;field_fieldname[1]-&gt;value;

// What basically happens internally for the above is:
$entity-&gt;get('field_fieldname')-&gt;get(0)-&gt;get('value')-&gt;getValue();