prevent entity from despawning

Post Reply
doctor_ew
New member
Posts: 3
Joined: Sun Feb 16, 2020 16:25
GitHub: v1nsai
In-game: doctor_ew

prevent entity from despawning

by doctor_ew » Post

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?

User avatar
GreenXenith
Member
Posts: 1337
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenXenith
In-game: GreenXenith
Location: The singularity
Contact:

Re: prevent entity from despawning

by GreenXenith » Post

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.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.

User avatar
runs
Member
Posts: 2190
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: prevent entity from despawning

by runs » Post

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.
I would like a callback when entity is unloaded cos map unloaded. So know where is saved.
🤑 Patreon |Minetest Chat | 👧 Samantha | ⛏️ Juanchi Game | 🐱 Petz

doctor_ew
New member
Posts: 3
Joined: Sun Feb 16, 2020 16:25
GitHub: v1nsai
In-game: doctor_ew

Re: prevent entity from despawning

by doctor_ew » Post

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.

User avatar
sorcerykid
Member
Posts: 1559
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: prevent entity from despawning

by sorcerykid » Post

runs wrote:
I would like a callback when entity is unloaded cos map unloaded. So know where is saved.
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.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests