prevent entity from despawning
prevent entity from despawning
I'm working on a grappling hook mod, and am trying to pull the player to the hook by attaching the player to the hook when it hits something. This works.....sometimes. I would say about 1 in 5. I suspect it is because the entity is despawning after it hits, so the set_attach attaches to nothing, but I'm having trouble figuring out how to control when it "dies". Is there a way to manually define this behavior?
- GreenXenith
- Member
- Posts: 1356
- Joined: Wed Oct 28, 2015 01:26
- GitHub: GreenXenith
- Location: UTC-8:00
- Contact:
Re: prevent entity from despawning
The entity should not just "despawn" when it hits something. The only reason an entity will despawn is because you tell it to, or it unloads because it isn't within an active mapblock.
You seem to be very unsure as to the reason, so I suggest doing a lot of debugging.
- Does set_attach even try to run? If it does and the entity doesn't exist, it should crash (I think).
- Does set_attach successfully attach to an entity? Is the player actually attached to something? If it looks like you haven't moved, the entity might not have moved.
- How do you know the entity is despawning? You can define an on_death method in the entity to see if something kills it, or print a message in on_step and see if it stops printing at any point (or do both just to be sure).
If it turns out your entity is in fact unloading due to unloaded mapblocks, you will need to manually load the area around it as it moves so it won't despawn.
If your entity is actually being removed for no apparent reason, let us know your findings and we can try to find the cause. Posting the entity definition would likely help at that point.
You seem to be very unsure as to the reason, so I suggest doing a lot of debugging.
- Does set_attach even try to run? If it does and the entity doesn't exist, it should crash (I think).
- Does set_attach successfully attach to an entity? Is the player actually attached to something? If it looks like you haven't moved, the entity might not have moved.
- How do you know the entity is despawning? You can define an on_death method in the entity to see if something kills it, or print a message in on_step and see if it stops printing at any point (or do both just to be sure).
If it turns out your entity is in fact unloading due to unloaded mapblocks, you will need to manually load the area around it as it moves so it won't despawn.
If your entity is actually being removed for no apparent reason, let us know your findings and we can try to find the cause. Posting the entity definition would likely help at that point.
YouTube | Mods | Patreon | Minetest Discord @greenxenith
You should not be able to read this message.
You should not be able to read this message.
Re: prevent entity from despawning
I would like a callback when entity is unloaded cos map unloaded. So know where is saved.GreenDimond wrote:The entity should not just "despawn" when it hits something. The only reason an entity will despawn is because you tell it to, or it unloads because it isn't within an active mapblock.
You seem to be very unsure as to the reason, so I suggest doing a lot of debugging.
- Does set_attach even try to run? If it does and the entity doesn't exist, it should crash (I think).
- Does set_attach successfully attach to an entity? Is the player actually attached to something? If it looks like you haven't moved, the entity might not have moved.
- How do you know the entity is despawning? You can define an on_death method in the entity to see if something kills it, or print a message in on_step and see if it stops printing at any point (or do both just to be sure).
If it turns out your entity is in fact unloading due to unloaded mapblocks, you will need to manually load the area around it as it moves so it won't despawn.
If your entity is actually being removed for no apparent reason, let us know your findings and we can try to find the cause. Posting the entity definition would likely help at that point.
Re: prevent entity from despawning
Thanks for that post, I was not aware that entities do not despawn without explicitly being told.
Knowing that, I just figured it out. I'm using the Eurythmia team throwing API, which was despawning it automatically. I spawned myself a normal entity to attach to and it works 100% of the time.
Knowing that, I just figured it out. I'm using the Eurythmia team throwing API, which was despawning it automatically. I spawned myself a normal entity to attach to and it works 100% of the time.
- sorcerykid
- Member
- Posts: 1847
- Joined: Fri Aug 26, 2016 15:36
- GitHub: sorcerykid
- In-game: Nemo
- Location: Illinois, USA
Re: prevent entity from despawning
I'm actually planning to open a PR for that, as there's already an on_deactivate callback in the Minetest S3 engine. So I think it's definitely warranted. Someone proposed such a callback a few years ago, but it was rejected by the core devs. So crossing fingers.runs wrote:
I would like a callback when entity is unloaded cos map unloaded. So know where is saved.
Who is online
Users browsing this forum: No registered users and 8 guests