Reference to Texture2D used in RuleTexture?

  • A* version: 5.4.4
  • Unity version: 6000.2.6f2

I’ve setup a Grid Graph rule that uses a Texture2D to determine walkability and penalty values. Perhaps a simple question: is there a way to reference the Texture2D set there in other scripts (I want to use it to calculate the exact pixel that corresponds to a transform’s position)?

Yep, you can do this:

void CheckGridGraphTexture(){
    var rulesList = AstarPath.active.data.gridGraph.rules.GetRules();
    var texture = ((RuleTexture)rulesList[0]).texture;
    
    Debug.Log(texture.name);
}

Logs:

GridBox_Default
UnityEngine.Debug:Log (object)
1 Like

Thanks for your help, that works great.

1 Like