OK, I’ve been working on a set of camera controls for simulation and strategy games, the idea being several swappable camera modes – a classic traditional mode (similar to Cities: Skylines), first person modes (similar to Minecraft creative mode), and variants with several discrete Y levels for things like stories in a building (thing of The Sims). To do this all camera controls (“modes”) extend an abstract class that acts as an interface with some common data attached. The problem is, some abstract methods are recognized while other give an error for not being implemented:
In the base class ACameraControl:
/// <summary>
/// This gets the position currently under under the cursor (center screen for first-person
/// views). This is intended for situations when some element most be moved constantly,
/// such as an effected spot marker. It needs to be nullable in case moved off the area.
/// </summary>
/// <returns></returns>
public abstract Vector3? GetCursorLocation();
/// <summary>
/// This gets the game object currently under under the cursor (center screen for first-person
/// views).
/// </summary>
/// <returns></returns>
public abstract GameObject GetCursorObject();
…later in a derive class…
public virtual Vector3? GetCursorLocation() {
Ray ray = playerEye.ScreenPointToRay(Input.mousePosition);
// Don't give a world position if on the UI
if(Physics.Raycast(ray, out RaycastHit hit, float.PositiveInfinity, UILayer)) {
return null;
}
if(Physics.Raycast(ray, out RaycastHit hit, playerEye.farClipPlane, groundPlainMask)) {
return hit.point;
}
// Don't give a world position if somehow off screen or not pointing a ground plain
return null;
}
public virtual GameObject GetCursorObject() {
Ray ray = playerEye.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out RaycastHit hit, float.PositiveInfinity, UILayer)) {
return null;
}
if(Physics.Raycast(ray, out RaycastHit hit, playerEye.farClipPlane, layerMask)) {
return hit.collider.gameObject;
}
return null;
}
Its there, plain as day, and my IDE sees it and thinks everything is good. But when returning to the Unity Editor I get errors flagged for this and every other derived class claiming that GetCursorObject() hasn’t been implemented, though it does recognize GetCursorLocation() as being implemented.
This is not the first time I’ve seen something like this happen, btw, just the latest. In the past re-arranging the order of the methods seemed to help, but not this time. I tried restarted the editor, in case it was stuck on some old data.
Is this a bug? – it sure looks like one. Otherwise, what is going on?
9412040–1318193–ACameraControl.cs (3.83 KB)
9412040–1318196–ClassicControl.cs (7.46 KB)