EVENT_BEFORE_SAVE event not getting $entry-id when creating an entry I don't know if it was with Craft 3.5, but did something change slightly when using the EVENT_BEFORE_SAVE event?
I have a simple use case where I am encoding the entry ID and updating the slug when the entry is saved.
It does check if a title is empty and if the entry is a draft or revision, if any of those are true, then it does not encode it.
After updating from Craft 3.4.30 to Craft 3.5.5 when saving an entry I have noticed that it throws an error as $entry-&gt;id returns null, however on refreshing the page and then resaving it, it passes the entry ID in fine.
A basic example of what I have is:
Event::on(
    Entry::class,
    Entry::EVENT_BEFORE_SAVE,
    function (ModelEvent $event) {

        $entry = $event-&gt;sender;

        if (ElementHelper::isDraftOrRevision($entry)) {
            return false;
        }

        // Get entry title
        $title = $entry-&gt;title;

       if ($title !== null) {
            // Encode entry ID
            $newSlug = Module::$instance-&gt;hashid-&gt;encode($entry-&gt;id);

            // Update slug to be a hash
            $entry-&gt;slug = $newSlug;
        }
    }
);

Before hand this worked fine when creating the entry, but now it is requiring me to have to save the entries twice, any thoughts?
I did some looking into how the EVENT_BEFORE_SAVE is being used and whether or not we can get the entry ID, without having to over complicate things, it was better to use EVENT_AFTER_SAVE, this does mean you will have to resave the entry after saving it, in this case that is very little overhead and it is only for a certain section, if heavier stuff was happening you may want to check on the impact.
I also placed in a check to detect if the action was happening or not, to stop any loops.
Here is what I ended up doing for anyone who wants to know for reference.
use craft\elements\Entry;
use craft\events\ModelEvent;

const SECTION_ID = 4;
public static $entrySlugRenaming = false;

Event::on(
    Entry::class,
    Entry::EVENT_AFTER_SAVE,
    function (ModelEvent $event) {
        $this-&gt;handleEventAfterSave($event);
    }
);

private function handleEventAfterSave($event)
{
    // Get entry
    $entry = $event-&gt;sender;

    // Don't worry about draft or revisions
    if (ElementHelper::isDraftOrRevision($entry)) {
        return;
    }

    // Test if entry renaming is already running
    if (!self::$entrySlugRenaming) {
        self::$entrySlugRenaming = true;

        // Check if there is an entry
        if ($entry !== null) {
            // Test for entry section
            switch ($entry-&gt;sectionId) {
                case self::SECTION_ID:
                    // Update slug here
                break;
            }
        }

        // Resave event
        $elements = Craft::$app-&gt;getElements();
        $elements-&gt;saveElement($entry);

        // Reset $entrySlugRenaming
        self::$entrySlugRenaming = false;
    }
}