The referenced script on this Behaviour (Game Object ‘Brute Warrior’) is missing!
You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor()
SA.TB.Node:.ctor() (at Assets/Grid/Node.cs:27)
SA.TB.GridBase:CreateGrid() (at Assets/Grid/GridBase.cs:89)
SA.TB.GridBase:InitPhase() (at Assets/Grid/GridBase.cs:36)
SA.TB.GridBase:Start() (at Assets/Grid/GridBase.cs:27)
I am following along with a turnbased strategy guide on youtube, I am at a part where the creator has gotten the purple line, most likely the pathfinder in action, to work. I thought that the yellow errors I keep getting would have something to do with why things aren’t working right. If you need me to type out any of the script I will do so. One thing that might have caused a problem is that instead of his “boxman” I used the brute from the Warrior Pack Bundle. Both the video and the warrior pack are as linked as follows.
Quick update: still having issues getting the pathfinder line to work, the error points me towards my Node script which goes as follows.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SA.TB
{
public class Node : MonoBehaviour
{
//Node's position in the grid
public int x;
public int y;
public int z;
//Node's costs for pathfinding purposes
public float hCost;
public float gCost;
public float fCost
{
get
{
return gCost + hCost;
}
}
public Node parentNode;
public bool isWalkable = true;
//Reference to the world object so we can have the world position of the node among other things
public GameObject worldObject;
//Types of nodes we can have, we will use this later on a case by case examples
public NodeType nodeType;
public enum NodeType
{
ground,
air
}
}
}
from what you said I’d guess that I would have to do something like:
}
}
public Node parentNode;
public bool isWalkable = true;
GetComponent();
//Reference to the world object so we can have the world position of the node among other things
public GameObject worldObject;
Or at least Node is what the error is pointing me to, it could actually have something to do with the GameManager, Pathfinder, or PathfindMaster, all of which are connected to moving and clicking the purple line so that the Brute can move. As I stated unlike in Sharp Accent’s video I’m not using his “Boxman” model so I’m worried that all my troubles have something to do with a code made specifically for his Boxman and not for the Brute I’m using. At the very moment I’m trying to get the Pathfinder line to move with my mouse so that I can continue on. If anyone knows any code fixes that can allow the pathfinder line to work it would e much appreciated.
Thank you for the help but I’m still stuck. I’m going to put up some of my script that I believe to be causing the problem.
GridBase.cs:
for (int x = 0; x < sizeX; x++)
{
for (int z = 0; z < sizeZ; z++)
{
Node n = new Node ();
n.x = x;
n.y = y;
n.z = z;
n.isWalkable = true;
if (debugNode)
{
Vector3 targetPosition = GetWorldCoordinatesFromNode (x, y, z);
GameObject go = Instantiate (debugNodeObj,
targetPosition,
Quaternion.identity
) as GameObject;
go.transform.parent = ylvl.nodeParent.transform;
go.SetActive (true);
}
grid [x, y, z] = n;
}
}
}
}
Node.cs:
return gCost + hCost;
}
}
public Node parentNode;
public bool isWalkable = true;
//Reference to the world object so we can have the world position of the node among other things
public GameObject worldObject;
GridBase.cs:
public void InitPhase()
{
if (debugNode)
debugNodeObj = WorldNode ();
Check ();
CreateGrid ();
GameManager.singleton.Init ();
isInit = true;
}
GridBase.cs:
void Start()
{
InitPhase ();
}
public void InitPhase()
{
if (debugNode)
debugNodeObj = WorldNode ();
Check ();
CreateGrid ();
The errors say:
You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor()
SA.TB.Node:.ctor() (at Assets/Grid/Node.cs:27)
SA.TB.GridBase:CreateGrid() (at Assets/Grid/GridBase.cs:90)
SA.TB.GridBase:InitPhase() (at Assets/Grid/GridBase.cs:36)
SA.TB.GridBase:Start() (at Assets/Grid/GridBase.cs:27)
So the problem should have something to do with Line 27 on Node.cs, 90 on GridBase.cs, 36 on GridBase.cs, and 27 on Gridbase.cs. Forgive me for being thickskulled. If anyone can finally point out where I went wrong it would be most appreciated if I’m just wasting time I’m sorry.
Make sure that the tutorial you’re following actually has those scripts declared as MonoBehaviours.
When you add a new script in Unity, it looks like this:
public class MyNewScript : MonoBehaviour { ... }
But it doesn’t have to inherit that class at all. You can also do:
public class MyNewClass { ... }
The very short version of it is that MonoBehaviours can be attached to gameobjects in the scene, while plain classes can’t. On the other hand, you can just make new instances of plain classes (using new MyNewClass()), while you can’t do that with MonoBehaviours.