Struggling with OnTriggerEnter

This is probably an incredibly easy problem for many, but I’m struggling here. I have a scene with a cable (long cylinder) and a capsule. Both have rigidbodies. The cable is set to IsTrigger. I found this script in Scripting APIs:

public class ExampleClass : MonoBehaviour {
void OnTriggerEnter(Collider other) {
Destroy(other.gameObject);
}
}

I modified it to the following:

using UnityEngine;
using System.Collections;
public class CableHook : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
Destroy(other.gameObject);
}
}

I attached the script to the Cable object. I run the scene and move the capsule through the cable…nothing happens. I started with just “Debug.Log(“Touched!”);” just to make the console register the event. Nothing happens. I also getting an error, “NullReferenceException: Object reference not set to an instance of an object.”

What gives? I’m using the script near verbatim and it still doesn’t work. I also don’t understand where the variable “other” is getting defined. Is it passed into the function? I don’t see where that happens. I’ve looked at tutorial after tutorial and always there’s this unexplained variable like “other” or “col”.

I must also point out that I’m trying to make a mod for a game called “Simple Planes” and they have their own editor addon. Could this be changing how things work?

Thanks for any help.

I’m guessing both have colliders and only one is set to trigger?

When do you get your null error?

Other is a parameter for the OnTriggerEnter. It’s passed in when it triggers.

Correct. Only the cable has a trigger. The capsule does not.

Error occurs even before I move the capsule.

You’ll need to fix that null error. Null errors will sometimes break the rest of the game which could prevent the rest of your game from running correctly. I’m not saying this will fix your issue, but that’s what I would look at first.

Also, is this a 2d or 3d game?

I don’t know simple planes to know if they could have changed anything, honestly.

The setup should be a simple two colliders. One set as trigger. One has a rigidbody (usually your player, but shouldn’t matter). One collider moves into the other. It’s OnTriggerEnter triggers, in your script it should destroy the player(capsule)

It’s a 3D game. I agree that error should be fixed, I just don’t know how. The error isn’t located in my script. Here’s the full text of the error.

"NullReferenceException: Object reference not set to an instance of an object
UnityEditor.InspectorWindow.OnSelectionChange () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:134)

System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[ ] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[ ] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[ ] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:187)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:180)
UnityEditor.HostView.OnSelectionChange () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:135)
UnityEditor.AssetDatabase:Refresh()
Jundroo.ModTools.Editor.ModBuilderWindow:SaveAssembly(String, Byte[ ])
Jundroo.ModTools.Editor.ModBuilderWindow:SaveProjectAssembly(FileInfo)
Jundroo.ModTools.Editor.ModBuilderWindow:SaveProjectAssemblies(String)
Jundroo.ModTools.Editor.ModBuilderWindow:Initialize()
Jundroo.ModTools.Editor.ModBuilderWindow:OnEnable()"

Thanks for stepping in. I appreciate that.