My entity procedure crashes the game

Section

If your procedure crashes the game when the procedure is called in some or all cases, you are probably using one of these procedure blocks (there are other blocks too, the common thing with these blocks is they have a special NULL marking):

Minecraft entity null

These blocks can return an empty value (null), as the entity will not always have an owner, be attacking, or riding another entity.

The cause

If you use such block in a procedure with any action, for example like this (just example, any use without a check shown in the next section is problematic):

Minecraft entity procedure example

In case the "Event/target entity" will not be riding any entity, you will be setting the health of an entity that does not exist to 0 in this case, and this will inevitably lead to a crash.

The solution

Whenever you use such a block, you need to ensure the entity you are looking for exists (is not NULL). To do this, you will need to check if your entity is one of the types you expect or check if the entity is not null directly. The corrected procedure from the example above in case we want the procedure to run for any living entity type would be:

Minecraft entity procedure block proper use for null

If you don't want to check for a specific type, alternative check can be

Now, we check if the entity "Event/target entity" is riding is of (sub)type EntityLiving (all animals, mobs, ...). The entity that is NULL is not a living entity, so in such case, this procedure will not run, and we will not be setting the health of a non-existent entity to 0 and the game will run happily.

Improved null check procedures

Starting with MCreator 2025.2, an improved null check procedure blocks were added. We recommend using those when possible. See some examples below - the grayed out procedure is the old approach explained above.

New null check procedure blocks in MCreator 2025.2

Disabling automatic dependency null check

To prevent crashes that beginners would not understand, by default, MCreator requires all dependencies that can be null not to be null. One major example is entity dependencies. If the procedure uses, e.g., both source and target entity dependencies, both need to be non-null for the procedure to run.

However, this may not always be the case, and in those cases, the procedure would currently not run. One can disable those null checks, but this requires them to then manually check if the entity is not null. Therefore, this is an advanced feature that only experienced procedure users should use.

Example of how the code changes if one disables the dependency null check in MCreator mod maker



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.