MeshRenderer Issues

I’m having issues getting this to work. My peach was falling but was not disappearing like it should have and I got an error stating:
MissingComponentException: There is no ‘MeshRenderer’ attached to the “Peach” game object, but a script is trying to access it.
You probably need to add a MeshRenderer to the game object “Peach”. Or your script needs to check if the component is attached before using it.
Dropper.Start () (at Assets/Scripts/Dropper.cs:16)"

I checked and there was indeed no Mesh Renderer on the peach, so I added that and it still does not work correctly. During play, Mesh Renderer is disabled but the peach doesn’t disappear and won’t fall. When I remove Mesh Renderer it starts falling again.
Unity_yMDifmvawZ
Unity_QTqWEWyrSc

My code so far:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Dropper : MonoBehaviour

{

MeshRenderer renderer;

Rigidbody rigidbody;

[SerializeField] float timeToWait = 5f;

// Start is called before the first frame update

void Start()

{

    renderer = GetComponent<MeshRenderer>();

    rigidbody = GetComponent<Rigidbody>();

   

    renderer.enabled = false;

    rigidbody.useGravity = false;

}

// Update is called once per frame

void Update()

{

    if(Time.time > timeToWait)

    {

        Debug.Log("3 seconds have elapsed");

    }

}

}

Check whether there is correct mesh in mesh renderer or there is no children under parent object which also containing this peach mesh.
Also In above code, you didn’t updated the renderer and rigidbody value after the time elapsed.

In update method, you have to add this:-
if(Time.time > timeToWait)
{
renderer.enabled = true;
rigidbody.useGravity = true;
}

That works thank youu! The problem I had was having an Empty Object with multiple prims
I hadn’t made it to the point of the video with that part of the script yet.

1 Like

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

Privacy & Terms