last spawned entity does not always return, it'll return none in some cases
simple code:
spawn a villager at location of {_p}
set {_villager} to last spawned entity
sometimes, with about 30% chance, {_villager} will be none while the villager did get spawned
I expect it to return villager entity at ALL times
None
I can not replicate this issue:
command /test:
trigger:
loop 20 times:
spawn a villager at spawn of world "world"
set {_v} to last spawned villager
send "Villlager: &a%{_v}% &7UUID: &b%uuid of {_v}%" to console
kill all villagers

I can not replicate this issue:
command /test: trigger: loop 20 times: spawn a villager at spawn of world "world" set {_v} to last spawned villager send "Villlager: &a%{_v}% &7UUID: &b%uuid of {_v}%" to console kill all villagers
oh you can, check the output more, some UUIDS are the same, you aren't deleting {_v}
Hmm, not sure then, Ill mark it as a bug.
I think it should be of higher priority than just low, because many people in their scripts that work with entities use "last spawned entity" and with it being unpredictable, it can really destroy their logic (like it did in mine)
changed
if anyone runs into the same issue before it is fixed, here's a temporary skript-mirror workaround:
import:
org.bukkit.entity.EntityType
function entityType(type: string) :: string:
switch {_type}:
case "ender dragon":
return "ENDER_DRAGON"
case "TNT":
return "PRIMED_TNT"
case "ender crystal":
return "ENDER_CRYSTAL"
case "armor stand":
return "ARMOR_STAND"
case "dropped item":
return "DROPPED_ITEM"
return {_type}
expression (spawn|summon) [custom] %entitytypes% at %location%:
get:
return (expression 2).getWorld().spawnEntity((expression 2), EntityType.valueOf((entityType("%expression-1%")).toUpperCase()))
This issue does not appear to affect newer versions at all, from what I can see.
While it might still be happening, it has not appeared in over a dozen tests on either my local or remote servers. It seems to be limited to outdated MC versions from what I can tell (I'm going to test 1.13 through 1.15 today)
EDIT: I've tested a bunch of versions. It seems to be absolutely fine in 1.14+ :)
1.12.2 (issue present - there are duplicate indices):

1.16.1 (issue presumably absent - no duplicate indices):

So turns out this was just a silly little typo in VillagerData.
Its always those teeny tiny things right!
Most helpful comment
if anyone runs into the same issue before it is fixed, here's a temporary skript-mirror workaround: