I tried buiding a game made with Unity by building objects I called WorldObjects. WorldObjects are spawned via a data class (WorldObjectData) that is governed by a manager (WorldObjectDataManager). The part that needs fixing is the process that spawns WorldObjects. Long story short, I have to pass two generic parameters to a WorldObject builder: the first one is the type of the WorldObject, the second one is the type of data class (so that the script can fetch the correct WorldObjectDataManager).
Error CS0029 Cannot implicitly convert type 'Sandbox.GUI.Sandbox.BuildButton.BuildMenuEntry<Sandbox.Selectables.Entities.JobInteractables.WorldObjects.Consoles.Console, Sandbox.Selectables.Entities.JobInteractables.WorldObjects.Consoles.ConsoleData>' to 'Sandbox.GUI.Sandbox.BuildButton.BuildMenuEntry<T, G>' Assembly-CSharp C:\Unity Projects\80s Sandbox\Assets\Scripts\GUI\Sandbox\BuildButtons\BuildButtonsChildren\BuildControl.cs 16 Active
This is the error I get when I try to compile line Console.GetEntry():
using Sandbox.Selectables.Entities.JobInteractables.WorldObjects;
using Sandbox.Selectables.Entities.JobInteractables.WorldObjects.Consoles;
namespace Sandbox.GUI.Sandbox.BuildButton // Used to spawn WorldObjects via a button
{
/// <summary>
/// BuildButton used for control buildings (e.g.: consoles)
/// </summary>
public class BuildControl<T, G> : CreateBuildButtonNew<T, G> where T : WorldObject where G : WorldObjectData
{
protected override BuildMenuEntry<T, G>[] GetBuildMenuEntries()
{
return new BuildMenuEntry<T, G>[]
{
Console.GetEntry()
};
}
}
}
Console.GetEntry is coded as follows:
public static BuildMenuEntry<Console, ConsoleData> GetEntry()
{
return new BuildMenuEntry<Console, ConsoleData> // Console and ConsoleData inherit from WorldObject and WorldObjectData respectively
{
entryName = UIStringID, // string
entrysMaterials = new WorldObjectMaterial[] { WorldObjectMaterial.Steel }, // WorldObjectMaterial is an enum
associatedFunction = InitializeByStatic<Console, ConsoleData> // the spawning function
};
}
Finally, BuildMenuEntry:
using Sandbox.Selectables.Entities.JobInteractables.WorldObjects;
namespace Sandbox.GUI.Sandbox.BuildButton
{
public struct BuildMenuEntry<T, G> where T : WorldObject where G : WorldObjectData
{
public string entryName;
public WorldObjectMaterial[] entrysMaterials;
public SpawnWorldObject<T, G> associatedFunction;
}
}
I have no idea what's the problem here since T and G are constrained to be respectively WorldObject and WorldObjectData, and Console.GetEntry returns a class whose generic types inherit from WorldObject and WorldObjectData.
Any help is greatly appreciated!