#Object gets deleted but it should not

1 messages · Page 1 of 1 (latest)

onyx pier
#

The title already says what the problem is

#

So I am working on a first person movement system and since I short time the player gets deleted after some time

#

If you need code just ask for it but I already checked it for "Destroy()" functions and other stuff

#

I also debugged some parts but the logs were inconsistent

onyx pier
#
RaycastHit hit;
if(Physics.SphereCast(origin + groundCheckOffset, groundCheckRadius, direction, out hit, maxDistance, whatIsGround, QueryTriggerInteraction.UseGlobal))
{
  currentHitObject = hit.transform.gameObject;
  grounded = true;

  //-----------This part is causing the problem-------------------------
  if(didLand) {
    //Dust Particle
     var dustObject = Instantiate(dust, feet.position, Quaternion.identity);
     Destroy(dustObject, 15);

     didLand = false;
   }
 }
 else
 {
   currentHitObject = null;
    grounded = false;
    //-----------This part is causing the problem-------------------------
    didLand = true;
  }
}
#
//-----------This function is causing the problem-------------------------
private void LerpCamPos()
{
  if(didLand = false) {
    head.localPosition = Vector3.Lerp(mainCam.localPosition, defaultCamPos, Time.deltaTime * 10f);
  }
}
#

I am not 100% sure if this is the problem but the mark code parts are maybe the issue

#

They are new to my code and when I remove them it works again

#

Thanks for anyone that tries to help

alpine sail
#

Before I continue

#

Wait actually nvm I thought you were using isGrounded

#

hm

#

Why are you inverting didLand?

onyx pier
alpine sail
#

is this all inside of Update()?

onyx pier
#

yes

alpine sail
#

and what is the spherecast for?

onyx pier
#

the errors are irrelevant

#

there are only there because the player got deleted and some script cant access the object anymore

alpine sail
#

so

#

what is your dust object set as

#

I'm assuming the prefab for dust but

#

can you double check that?

#

in the editor

onyx pier
#
[SerializeField] private GameObject dust;
#

wait i will remove it from my code

#

lets see if its the issue

alpine sail
#

good call

#

check everywhere in your project where you call Destroy too

onyx pier
#

yup still there

#

but i noticed something

#

it happens when i stand still after a bunny hop or something

#

check the first clip

alpine sail
#

and your character does disappear right

onyx pier
onyx pier
#

look in the hierachy

alpine sail
#

hmm

#

so player is getting deleted but not character

onyx pier
#

well yea

#

the modell is a seperated object like the camera

#

the script dont affect them

alpine sail
#

I have no idea like

#

Destroy isn't getting called anywhere else yea

onyx pier
#

Yea thats my problem

#

I am just gonna remove it

#

I will look to work arround it

alpine sail
#

yeah, I'm not sure where the issue would be in your code, I'd have to look

onyx pier
#

i am not sure either

#

i will just try changing to a newer version