Target selectors do not work reliably in functions tagged minecraft:load when the world is loading - but not simply when datapacks are reloaded.
Steps to reproduce:
Create a datapack with four files (attached):
data/test/functions/test/onload.mcfunction
execute unless entity @e[tag=tester] run function test:test/reboot
data/test/functions/test/reboot.mcfunction
execute as @e[tag=tester] run say rebooting kill @e[tag=tester] summon armor_stand ~ ~ ~ {Marker: 1b, NoGravity: 1b, Silent: 1b, Invisible: 1b, Tags:["tester"]} execute as @e[tag=tester] run say rebooted
data/test/functions/test/rollcall.mcfunction
execute as @e[tag=tester] run say hi
data/minecraft/tags/functions/load.json
{"values": ["test:test/onload"]}
Create a world. Add this datapack manually.
Enter the world and run the following. Observe that one armor stand responds with "rebooting" then with "hi" - as expected.
/reload
/function test:test/rollcall
Run the following. Observe that one armor stand responds with "hi", indicating that reboot was not called - as expected.
/function test:test/onload
/function test:test/rollcall
Save, exit, and reload the world.
Run the following. Observe that two armor stands respond with "hi". This means that onload then reboot were called - not as expected. The kill command did not work and the summon command did, since it has no target selector to fail. The target selectors in onload and reboot both fail to find entities. Observe also that no armor stand responds with "rebooting" and one armor stand responds with "rebooted" in the game output - not as expected, since there are one and two entities at those times, respectively.
/function test:test/rollcall
Run the following. Observe that still two armor stands respond with "hi", indicating that reboot was not called - as expected. This indicates that the issue is unique to world load, and not just any datapack reloading.
/reload
/function test:test/rollcall
Run the following. Observe that two armor stands respond with "rebooting", then one with "rebooted", then one with "hi", indicating that reboot does work after the world is loaded - as expected.
/function test:test/reboot
/function test:test/rollcall
What was expected
Target selectors work on world load so that, in the example above, reboot is not run again when the world is reloaded.
Does MC-145442 describe this issue? The #minecraft:load function tag can run before the world is completely loaded.
A simple workaround is to repeatedly schedule a function until a player joins the world: