Having issues with GetComponent<>()

I’ve been changing/adding code to the TurnbasedManager script and when trying to access a component in one of the newly added Node Prefabs (one of the squares that appears to show where you can move), it is giving me an error that says “the type or namespace ‘NodeProperties’ could not be found.”

I am able to access the script in other scripts that I have written, so I am a little confused.

I’d love some help! Thank you.

possibleMoves[0].GetComponent();

Hi

The pathfinding scripts are compiled separately by unity (see assembly definition files in the unity docs). I’d recommend that you create a new script outside the A* package and edit that. There you will be able to access both the pathfinding scripts and your other scripts.

Thanks for the reply!

I copied the whole script (and renamed it) and changed AstarSplines to a public class instead of a static class so the line below could run. Is this going to royally give me problems in the future? So far it seems to be working and I can now reference other scripts.

var interpolatedPoint = AstarSplines.CatmullRom(p0, p1, p2, p3, distanceAlongSegment / segmentLength);

1 Like

Hi

AstarSplines is already a public class… so I’m not sure what you mean.

Either way I don’t think this approach should lead to any issues.

For whatever reason for me it was static. Maybe Unity changed it somehow. Thank you for the help!

It is public and static. They are not mutually exclusive:

public static class AstarSplines {
    ...
}

In any case, I’m glad it works for you now :slight_smile:

1 Like

(I’m not sure if it would be better to make a new topic or just reply here but…)

I am having trouble accessing the new TurnBasedManager_ script that I copied over from before. While I can access other scripts from it, but am unable to access it through other scripts. I am trying to call a function that I made in the new TBSManager script but cannot.

Any help or suggestions would be much appreciated!

The TBSManager script is set up like this:
public class TurnBasedManager_ : MonoBehaviour

Line that doesn’t work:
turnBasedManager.GetComponentComponent<TurnBasedManager>().BeginPlayerMovement(everyoneInBattle_[unit]);

Hi

Are you creating it inside the AstarPathfindingProject folder by any chance? Any scripts inside that folder will not be able to access any scripts outside it, since it is compiled as a separate dll by Unity.

Both the BattleSystem (the script that is trying to access the new copied TurnBasedManager script) and the new TurnBasedManager script are both in my Asset/scripts folder.

The TurnBasedManager can access the BattleSystem script but not the other way around.

EDIT: Could it be an issue with the TurnBasedManager using the namespace Pathfinding.Examples?

EDITx2: I just needed to add using Pathfinding.Examples to my BattleSystem script. Now I can access it! Thank you.

1 Like