Jump to content

Entity.IsValid() vs. Entity.Exists()


Vaskulis

Recommended Posts

Always use Entity.Exists(). This is an extension method and thus will not crash if Entity is null. It calls Entity.IsValid if the entity is not null.

 

Entity also has an implicit boolean operator that automatically calls Entity.Exists().

My YouTube: Click here. 

My Discord Server - https://discord.gg/0taiZvBSiw5qGAXU

Useful post? Let me and others know by clicking the Like button.
Check out my many script modifications! 
Having issues? LSPDFR Troubleshooter by Albo1125.

Link to comment
Share on other sites

1 minute ago, Albo1125 said:

Always use Entity.Exists(). This is an extension method and thus will not crash if Entity is null. It calls Entity.IsValid if the entity is not null.

 

Entity also has an implicit boolean operator that automatically calls Entity.Exists().

 

Okay, that makes sense, thank you!

Link to comment
Share on other sites

I havent had any issues switching to just if (entity) and using the implicit operator, it checks both ==null and .Exists() quite nicely.

My YouTube Channel: Darkmyre Gaming (Australian LSPDFR patrols, plugins in development, and other games)

My Discord Server | AusGamer Network

 

Please do not PM me for technical support or bug reports, use the appropriate forum or plugin's comments instead.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...