Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type coercion in Impact() causes ticking error #1

Open
kyleoneill opened this issue Feb 14, 2020 · 1 comment
Open

Type coercion in Impact() causes ticking error #1

kyleoneill opened this issue Feb 14, 2020 · 1 comment

Comments

@kyleoneill
Copy link

kyleoneill commented Feb 14, 2020

The code hitThing is Pawn hitPawn in the if statement of the Impact override causes the following exception in Rimworld. I used Visual Studio Community 2019 as my compiler.

Exception ticking Bullet_PlagueGun46757: System.NullReferenceException: Object reference not set to an instance of an object at Plague.Projectile_PlagueBullet.Impact (Verse.Thing hitThing) [0x00000] in <filename unknown>:0 at Verse.Projectile.ImpactSomething () [0x00000] in <filename unknown>:0 at Verse.Projectile.Tick () [0x00000] in <filename unknown>:0 at Verse.TickList.Tick () [0x00000] in <filename unknown>:0 Verse.Log:Error(String, Boolean) Verse.TickList:Tick() Verse.TickManager:DoSingleTick() Verse.TickManager:TickManagerUpdate() Verse.Game:UpdatePlay() Verse.Root_Play:Update()

The error can be fixed by adding a new if statement to check if the hitThing is a Pawn, like if (hitThing is Pawn) and putting the rest of the code for Impact inside the block.

@Mehni
Copy link
Contributor

Mehni commented Feb 23, 2020

That's not Type coercion; it's pattern matching. It's nullsafe.

Make sure to use hitPawn in the rest of your code, not hitThing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants