(I *DID NOT* find a solution) "The type or namespace name 'PlaceableObject' could not be found..." Tutorial is failing and I am a *beginner* beginner!!! SEND HELP

The last time I posted this it was closed because a moderator misread a comment of mine referring to an issue I found the solution to while writing the post about the post, not the solution to the issue in Unity.

The post went as follows:

Unity being pain rn

I’m a true beginner and having trouble getting code from a tutorial to work. Am planning to go back later to understand it all when this system works, but I can’t get this error to go away and have no idea what’s wrong.

error is line 18, coords are (18,13)

the tutorial: 3D Grid Building System - Unity Tutorial | City Builder, RTS, Factorio - YouTube

The code: (BuildingSystemGround)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Tilemaps;
 
 public class BuildingSystemGround: MonoBehaviour
 {
     public static BuildingSystemGround current;
 
     public GridLayout gridLayout;
     private Grid grid;
     [SerializeField] Tilemap MainTilemap;
     [SerializeField] TileBase whitetile;
 
     public GameObject prefab1;
     public GameObject prefab2;
 
     private PlaceableObject objectToPlace;
 
 #region Unity methods
 
     private void Awake()
     {
         current = this;
         grid = gridLayout.gameObject.GetComponent<Tilemap1>();
     }
 
     private void Update()
     {
         if (Input.GetKeyDown(KeyCode.A))
         {
             InitializeWithObject(prefab1);
         }
         else if (Input.GetKeyDown(KeyCode.B))
         {
             InitializeWithObject(prefab2);
         }
     }
 
 #endregion
 
 #region Utils
 
 public static Vector3 GetMouseToWorldPosition()
 {
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if (Physics.Raycast(ray, out RaycastHit raycastHit))
     {
         return raycastHit.point;
     }
     else
     {
         return Vector3.zero;
     }
 }
 
 public Vector3 snapCoordinateToGrid(Vector3 position)
 {
     Vector3Int cellPos = gridlayout.WorldToCell(position);
     position = grid.GetCellCenterWorld(cellPos);
     return position;
 }
 
  #endregion
 
  #region BuildingPlacement
 
     public void InitializeWithObject(GameObject prefab)
     {
         Vector3 position = snapCoordinateToGrid(Vector3.zero);
 
         GameObject obj = Instantiate(prefab, position, Quaternion.identify);
         objectToPlace = obj.GetComponent<PlaceableObject>();
         obj.AddComponent<ObjectDrag>(objectToPlace);
     }
 
  #endregion
 }

(end of "BuildingSystemGround)

have slightly more code here under another script, ObjectDrag:

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ObjectDrag : MonoBehaviour
 {
     private Vector3 offset;
 
     private void OnMouseDown()
     {
         offset = transform.position - BuildingSystem.GetMouseToWorldPosition();
     }
 
     private void OnMouseDrag()
     {
         Vector3 pos = BuildingSystem.GetMouseToWorldPosition() + offset;
         transform.position = BuildingSystem.current.SnapCoordinateToGrid(pos);
     }
 
 
 }

(end of “ObjectDrag”)

SORRY THE PROGRAM MESSED UP THE CODE THERE ARE HASHTAGS (this was the problem with the editor I had said I found the solution to by noticing the “insert code snippet” button in the text editor here in my comment. The moderator completely misread it and I ended up getting NO answer to my ACTUAL issue)

The space:

Tutorials are means to be followed exactly. At this timestamp she creates all the scripts in one go. Did you do that? Because the second script she creates is the PlaceableObject. Once created and Unity compiles without any error, there is now a type called PlaceableObject. So it’s impossible to get the error you got unless you did not do what she did. Note that if you for example mistyped the name initially, you can not simply rename the script because you need to fix the actual classname as well. When you create a script file, Unity is using a template and names the class the same as the file. This is a requirement. When you later rename the file the class would not be renamed. The same is true the other way round. When you rename the class, the file is not automatically renamed. You have to keep them in sync yourself if you change the name.

There’s not much to say about that. The error

The type or namespace name ‘PlaceableObject’ could not be found…

Always means the same. There is no type named “PlaceableObject”. Since that type was created in the tutorial, you either have missed it, mis-named it or did something else wrong.

The class’s name is BuildingSystemGround

in the ObjectDrag script you didn’t write well.
I also want to clarify that to access a function just make it static and you can access it with NameClass.Function.
So this variable is useless

  • public static BuildingSystemGround
    current;

  • Also make sure you have created the
    PlaceableObject class

    private void OnMouseDown()
       {
           offset = transform.position - BuildingSystem.GetMouseToWorldPosition();
       }
    
       private void OnMouseDrag()
       {
           Vector3 pos = BuildingSystem.GetMouseToWorldPosition() + offset;
           transform.position = BuildingSystem.current.SnapCoordinateToGrid(pos);
       }
    

I’ve fixed that error, but now I have more (gridlayout and BuildingSystemground apperantly dont exist or something, addComponent, what, NEEDS an OVERLOAD!? (Isnt that generally a bad thing!?)) and I’m considering maybe I should just start somewhere with more on it for a first serious Unity attempt… lol if you know how to make an editable 3d building grid for ingame topdown building to get me started on it that would be gr8 and I would love to get it working first and try to understand it later, but without a faultless Rosetta Stone for me to look at I think I’mma just try somewhere simpler and work my way up (again), like I’m supposed to and like I tried to (My first unity attempt was 2d with a spaceship, but couldn’t get movement and camera working well, so I swapped to something I thought would be simpler than a randomly generated open world spaceship game with a ship upgrading system and a movement system with about NO (video) documentation lololol) I thought a highscore game would generally just be easier because, but nah I’ll get back to this game when I’ve got more experience I guess. Thanks for the help tho