#Object gets deleted but it should not
1 messages · Page 1 of 1 (latest)
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
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
Before I continue
Wait actually nvm I thought you were using isGrounded
hm
Why are you inverting didLand?
so the particle (dust) only gets called once after you land
is this all inside of Update()?
yes
and what is the spherecast for?
ground check
the errors are irrelevant
there are only there because the player got deleted and some script cant access the object anymore
so
what is your dust object set as
I'm assuming the prefab for dust but
can you double check that?
in the editor
yea a prefab
[SerializeField] private GameObject dust;
wait i will remove it from my code
lets see if its the issue
yup still there
but i noticed something
it happens when i stand still after a bunny hop or something
check the first clip
and your character does disappear right
it gets deleted
look in the hierachy
well yea
the modell is a seperated object like the camera
the script dont affect them
yeah, I'm not sure where the issue would be in your code, I'd have to look