How do I toggle trail renderer emission on pickup object?

I have a pickup object called “Pen” with a collider, mesh renderer, and an Udon behavior component containing the graph “ink”. Then I have a Unity trail object called “Trail” that is a parent of “Pen”, and is essentially an empty with a trail renderer component.
image

I would like to turn the “Emitting” checkmark on if the player is holding down the use button while having the “Pen” gameobject in hand, and turn the checkmark off if the player lets go off the use button.
image

I have never used Udon before, I don’t even know how to reference a game object, I am an absolute beginner, but I spent all day trying to get something to work and I am desperate.

Welcome, RoboGuy!

Most nodes in Udon call things in the Unity Engine itself, so when you want to build something in Udon, a good first step is to figure out how it works in Unity. In this case, a quick search of the Unity Documentation reveals that you can control the ‘emitting’ property of a TrailRenderer.

The VRChat Docs then tell us that Pickup objects have OnPickupUseUp and OnPickupUseDown events. The UdonExample scene shows some ways to use these.

So we know we want to set the TrailRenderer.emitting property to ‘true’ when someone uses the pickup, and set it to ‘false’ when they stop using the pickup.

We can learn how to easily use Drag and Drop for GameObjects and Components in the VRChat Docs, this lets us get a reference to our TrailRenderer.

Put all that knowledge together, and you get this working graph that controls a TrailRenderer from OnPickupUseUp/Down:
image

Here it is in action: Screen capture - a92dcbaf5f333399edcf2d48405f8843 - Gyazo

1 Like

Thank you so much!