Player sprite gets invicible

GIF_Short
Hi,
My player gets invicible after implementing the flash routine. If i comment out the routine it does not happend. I cant understand what is different then the enemy except the movement. it seems to happen after i flash and then move around. Would love some help to figure out what is happening. Thanks.

The player is intended to be invincible (for a short time) after taking damage. The DamageRecoveryRoutine() method in PlayerHealth should be deactivating the player’s invincibility:

    private IEnumerator DamageRecoveryRoutine() {
        yield return new WaitForSeconds(damageRecoveryTime);
        canTakeDamage = true;
    }

However if you mean the player is turning invisible after taking damage, which seems to be what your picture shows, I’m not sure what the cause would be. It looks to me like your player is missing frames from the walking animation, or possibly the sprite is rendering below the tile map during those frames.

I would guess something strange is happening with the player’s Sprite Renderer as a result of the Flash script. Perhaps the defaultMat material isn’t being set correctly?

the routine is setup correctly and it does not happen with the slime so its not the flash itseöf that is the problem i guess.
The material is changing back to the default one in the inspector. and i tried to up the sorting layer just to test but that was not the problem either.
I am usually pretty good at bug fixing but i cannot understand the problem at all here =(

okey i figured out something now. If i run and get hit the idle animation is making the player invicible. If i idle when hit the run animation is making the plaeyr invicible. So the opposite animation every time so to speak. But why that happend i have no clue at all.

I can’t think of a reason for that to happen either. Hopefully someone else will have an idea!

I’m honestly not sure. It took me a second to figure out if you were saying Invisible (not seen) or Invincible (Superman), but I zoomed the video and could see it. Honest, it still looks to me like it’s a sorting layer issue.

So this is only happening after a flash has occurred?

oh sorry english is not my native language :sweat_smile:.
I put the sorting layer on top of everything but it still happens.

Yes it only happens after a flash has occurred.
And if i first get hit while running the idle is invisble and if i then get hit while idle the idle is okey again but the running is invisible.

I honestly have no clue, then. Zip up your project and upload it to https://gdev.tv/projectupload and I’ll take a look. Be sure to remove the Library folder to conserve space.

Thank you, I have uploaded it now :slight_smile:

Thanks, I’ll take a look at it after work.

I went through the project as thoroughly as I could and could find no reason for this effect. Sure enough, when one animation was active when the flash hit, it would be disabled and the opposite animation would work correctly and vice versa.

I compared the code and setup to the course repo and could find no significant differences, so I decided to upgrade my copy of the course repo to 2023.2.2f1 (the course repo is in 2022.2.2f1). Sure enough, the course repo exhibited the exact same behavior.

This leads me to conclude that it is a Unity bug within the 2023.2 version.

Thank you for your help. And nice to hear that I was not going crazy with this bug since i couldn’t find any problem.
Do you think I should try to downgrade the project?

Unfortunately, downgrading the project directly is not an option. Unity projects are not backwards compatible.

You can create a new project in a 2022 version, and copy the contents of the Assets folder to the new project, or you can start from scrach.

Or you could deactivate the flash for now and you should be able to continue the course.

I see. Then i think i Will deactivate the flash for now and have a flicker and hope that this Will be fixad innan uppdateringen version of 2023.
Thank you so much for the help! :smiley:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms