I’m in the “SendMessage() Between Components” video… and my send message does not work … the code on the collisionhandler.cs is
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollisionHandler : MonoBehaviour
{
// SHIPPING DATA //
// CHANGING DATA //
// * CODE * //
void OnTriggerEnter(Collider other)
{
StartDeathSequence();
}
private void StartDeathSequence()
{
print("player is dying");
SendMessage("OnPlayerDeath");
}
}
and the method on playercontroller.cs
void OnPlayerDeath() // RENAME WARNING called by string reference in CollisionHandler.cs
{
print("controls frozen");
}
all i get is “player is dying” in the console, so the method StartDeathSequence is called but the message isn’t received on the player controller
I’m able to move on with the course after much help in the discord, but this does not answer my question so please do not mark solved… I was told to use
{
print("player is dying");
GetComponent<PlayerController>().OnPlayerDeath();
}
and that works for now so I can move on, but it’s not been taught yet… why didn’t SendMessage work?
To which game object are the CollisionHandler and the playercontroller script assigned? To the same?
I was not able to find a bug related to your problem in Unity’s issue tracker. If you cannot find a solution, I would suggest to report a bug to Unity via Help > Report a bug.
If you sent a bug report to Unity, we could leave this thread open for a while, so you can post their answer here if you want. Otherwise, I could simply close this thread and leave it “unsolved”.