Guide: Autoloading textures and why am I getting this "Terraria.ModLoader.Mod.GetTexture(String name)" error?
Alright, hopefully someone has directed you here since you posted an error that looks like this:
I'm here to help you understand why this is happening, so read on.
The first think to understand is how tModLoader knows what texture you want to associate with your Item, Projectile, or NPC. You probably have something like this in your Mod class:
Code:
namespace SummonersAssociation
{
public class SummonersAssociation : Mod
{
public SummonersAssociation()
{
Properties = new ModProperties()
{
Autoload = true,
};
}
}
}
Here we are telling tModLoader to autoload, meaning all your ModItems, ModProjecties, etc will be loaded automatically and the path to the associated texture file will automatically be created. This is the desired behavior for 95% of all mods, but you need to follow some conventions so you place your texture file will be in the correct location.
Here is the expected texture path: namespace + classname with the "." replaced with "/".
Example:
Code:
namespace SummonersAssociation.Projectiles
{
public class BloodTalismanProjectile : ModProjectile
{
....
In the above example, the namespace is "SummonersAssociation.Projectiles" and the classname is the "BloodTalismanProjectile". Going off the autoloading convention, tModLoader will expect your png file to be located in: "\Terraria\ModLoader\Mod Sources\SummonersAssociation\Projectiles\BloodTalismanProjectile.png"
If it's not, you'll get the error.
Recap:
The full classname -- SummonersAssociation.Projectiles.BloodTalismanProjectile
Expected texture -- SummonersAssociation/Projectiles/BloodTalismanProjectile.png
Some things to remember:
- The filename of the .cs file doesn't matter AT ALL. (but it is useful for your sanity/organization for it to match the classname)
- Textures must be .png files.
- Expected texture path = namespace + classname with the "." replaced with "/". (as in subfolders)
- To fix the error, either correct the namespace or the folder and filename of the png.
- If you name your .cs files the same as the class it contains and keep the cs files in a subfolder that match the namespace, it should be easy to keep things organized and autoloading properly.
- CAPITALIZATION matters!