- Home /
Unable to Reference a Class
Hi,
I'm using the A* Pathfinding project (https://arongranberg.com/astar/docs/beginner.html), and have come across a seemingly simple problem.
I am trying to access the A* Seeker class from one of my scripts. I have the using Pathfinding;
directive at the top of the class but it is still not being able to be referenced/accessed.
have solved this problem before by moving the scripts into the same folder, but am wondering if there is another way to accomplish this.*
Thank you for any time and help.
EDIT :
To clarify, I downloaded the A* project and they have set themselves up in their own folder OUTSIDE of my scripts folder. In my scripts folder, I have created a script that tries to access/reference a script inside the A* folder. using Pathfinding; (the appropriate directive to the relevant namespace as evidenced by the other scripts/examples in the A* project) does not allow me to access/reference the script Seeker. I have solved this problem before by placing the custom script in the same folder as the Seeker script but am wondering how else to solve this, or at least why this is not resolving. Thank you.
Answer by Bunny83 · Nov 09, 2021 at 03:42 PM
I haven't used the path finding project myself before. However I just downloaded the package, imported it into my test project and I have no issues accessing the classes. Note that the pathfinding project needs to be in its own seperate folder, since it has an assembly definition file which will instruct the Unity editor to compile the whole folder into a seperate assembly.
You said
it is still not being able to be referenced/accessed.
what exact error do you get in Unity?
Hi, thanks for your reply.
The error is : Assets\Scripts\StateMachine\005_21Sept24\TEST_Enemy_Basic_005.cs(12,10): error CS0246: The type or namespace name 'Seeker' could not be found (are you missing a using directive or an assembly reference?)
.
Again, if I create a custom script outside of the A* Project folder, it cannot reference/access the Seeker
class, but if placed inside the A* Project folder, it is able to be accessed.
In my completely new custom script, I have only placed using Pathfinding;
at the top. Am I missing something? Or maybe not "installing" the A* Project appropriately? (Simply importing the A* Project.)
Thanks for your time and help.
EDIT :
I just made a brand new project, imported the A* Project and attempted to do the same thing. I was able to access/reference the Seeker
class from my custom script placed in a separate folder from the A* Project. The only thing I can think of that is done differently is the that my first (problematic) project is using the URP and whatever assemblies necessary and just being 2D.
Is it possible that the "StateMachine"folder also has an assembly definition file? You may have placed your script into a folder where you shouldn't. If that folder does have it's own assembly definition file you have two options:
Move the file out of that folder so it becomes part of the normal compilation group.
The second solution is to make the pathfinding assembly a dependency of that assembly where your script belongs to.
Hi again, thanks for your continued support.
There is no assembly definition file in the StateMachine
folder, but there is an .asmdef file in the same folder that houses the StateMachine
folder (the Scripts
folder contains both the StateMachine
folder and the .asmdef file in question; 1) Assets/Scripts/StateMachine
, 2) Assets/Scripts/Scripts.asmdef
).
Sorry, I'm a little unsure of which file you mean to move in your first solution. And the second solution I'm ignorant as how I would do that. I will try to pursue both solutions as soon as I am able, but any direction would be greatly appreciated.
Thank you again for your help and time!