tModLoader How do I spawn a NPC and catch its instance in a variable?

AthosE.

Official Terrarian
EDIT: This code is used on UseItem function. Then I return true for the item.type's value.

EDIT 2: I can now summon them, but it summons several copies, still need help, codes on the second post below.

I'm trying to make an item which spawns an NPC, but I have to change some of its variables AFTER it spawns, to do so, I have to reference its instance into a variable and then try to change it, but whenever I do, it says I'm missing a reference to an instance...


Example:
Code:
int id = NPC.NewNPC((int)player.position.X, (int)player.position.Y, modItem.summonNPC);
NPC summonedNPC = Main.npc[id];
NPCEdits modSummonedNPC  = summonedNPC.GetGlobalNPC<NPCEdits>();
modSummonedNPC.variable = value;

but it always returns an error, any help?
 
Last edited:
I'm trying to make an item which spawns an NPC, but I have to change some of its variables AFTER it spawns, to do so, I have to reference its instance into a variable and then try to change it, but whenever I do, it says I'm missing a reference to an instance... Example:


Code:
int id = NPC.NewNPC((int)player.position.X, (int)player.position.Y, modItem.summonNPC);
NPC summonedNPC = Main.npc[id];
NPCEdits modSummonedNPC  = summonedNPC.GetGlobalNPC<NPCEdits>();
modSummonedNPC.variable = value;

but it always returns an error, any help?

EDIT: This code is used on UseItem function. Then I return true for the item.type's value.
Hello AthosE,

I think this is an issue with your GlobalNPC class. Does the error you're getting show which file the error happens and on which line number? If so, could you post the contents of that file, together with the line number the error occurs? Additionally, could you post the contents of your GlobalNPC class (if that's not the same class the error occurs)?
 
Hello AthosE,

I think this is an issue with your GlobalNPC class. Does the error you're getting show which file the error happens and on which line number? If so, could you post the contents of that file, together with the line number the error occurs? Additionally, could you post the contents of your GlobalNPC class (if that's not the same class the error occurs)?

Yes. Sure. The purpose here is to summon an npc that acts like a minion. AI is still empty, will do once the summoning issues are dealt with.

The summoning is now happening, but it summons SEVERAL copies of the same NPC and there's an error saying there's an undefined object reference for an object instance. At line 986 which is at ---------player.slotsMinions += modMinion.minionSlots;

I should ask you to ignore anything related to AIs or Sprites right now, the code is not done.

Code:
using ClassOverhaul.UI;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using System;

namespace ClassOverhaul
{
    public class NPCEdits : GlobalNPC
    {
        public override bool InstancePerEntity => true;
        public override bool CloneNewInstances => true;
        public int atkCooldown = 0;
        public int atkSpeed = 30;
        public int defaultAtkSpeed = 30;
        public bool isMinion;
        public int owner;
        public int minionSlots;
        public int minionNum;
        public int minionPos;
        public int numUpdates;
        public int damage;
        public int knockback;
        public int shoot;
        public float shootSpeed;
        public float idleAccel;
        public float spacingMult;
        public float viewDist;
        public float chaseDist;
        public float chaseAccel;
        public float inertia;
        public float shootCool;

        public override void SetDefaults(NPC npc)
        {
            base.SetDefaults(npc);
            if (npc.type == NPCID.BlueJellyfish)
            {
                npc.catchItem = ItemID.BlueJellyfish;
            }
            if (npc.type == NPCID.PinkJellyfish)
            {
                npc.catchItem = ItemID.PinkJellyfish;
            }
            if (npc.type == NPCID.GreenJellyfish)
            {
                npc.catchItem = ItemID.GreenJellyfish;
            }
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            if (modNPC.isMinion == true)
            {
                npc.aiStyle = 0;
                npc.noTileCollide = false;
                npc.noGravity = true;
            }
        }
        public override void AI(NPC npc)
        {
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            if (modNPC.atkCooldown > 0) atkCooldown -= 1;
            if (modNPC.atkCooldown < 0) atkCooldown = 0;
            if (isMinion == true)
            {
                Check(npc);
                base.AI(npc);
                numUpdates++;
            }
            else
            {
                base.AI(npc);
            }
        }

        public override void OnHitPlayer(NPC npc, Player target, int damage, bool crit)
        {
            base.OnHitPlayer(npc, target, damage, crit);
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            modNPC.atkCooldown = modNPC.atkSpeed;
        }

        public override void ResetEffects(NPC npc)
        {
            base.ResetEffects(npc);
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            modNPC.atkSpeed = modNPC.defaultAtkSpeed;
        }

        public override bool CheckDead(NPC npc)
        {
            if (base.CheckDead(npc) && npc.type == NPCID.WallofFlesh)
            {
                PlayerEdits modPlayer = Main.player[Main.myPlayer].GetModPlayer<PlayerEdits>();
                modPlayer.defeatedWoF = true;
                modPlayer.immune = true;
                JobSelection.visible = true;
            }
            return base.CheckDead(npc);
        }

        public void Check(NPC npc)
        {
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            Player player = Main.player[modNPC.owner];
            PlayerEdits modPlayer = player.GetModPlayer<PlayerEdits>();
            if (player.dead)
            {
                modPlayer.Imp = false;
            }
        }

        public override bool CanHitPlayer(NPC npc, Player target, ref int cooldownSlot)
        {
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            if (Main.player[modNPC.owner] == target)
            {
                return false;
            } else
            {
                return base.CanHitPlayer(npc, target, ref cooldownSlot);
            }
        }
    }
}

Code:
        public override bool UseItem(Item item, Player player)
        {
            ItemEdits modItem = item.GetGlobalItem<ItemEdits>();
            if (modItem.hasSummon == true)
            {
                SummonMinion(item, player);
                return true;
            }
            return base.UseItem(item, player);

Code:
 public void SummonMinion(Item item, Player player)
        {
            ItemEdits modItem = item.GetGlobalItem<ItemEdits>();
            int id = NPC.NewNPC((int)player.Center.X, (int)player.Center.Y, modItem.summonNPC);
            NPC minion = Main.npc[id];
            NPCEdits modMinion = minion.GetGlobalNPC<NPCEdits>();
            modMinion.owner = Main.myPlayer;
            modMinion.minionPos = player.numMinions;
            if ((modMinion.minionSlots + player.slotsMinions) > player.maxMinions)
            {
                minion.life = 0;
            }
            else
            {
                player.numMinions++;
                player.slotsMinions += modMinion.minionSlots; //error here
                PlayerEdits modPlayer = player.GetModPlayer<PlayerEdits>();
                modPlayer.playerOwnedMinions.Add(minion);
            }
        }

Edit:
NPC being tested with:

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;

namespace ClassOverhaul.Minions
{
    public class Imp : ModNPC
    {
        public override void SetDefaults()
        {
            base.SetDefaults();
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            npc.width = 32;
            npc.height = 32;
            npc.lifeMax = 300;
            npc.life = 300;
            npc.stepSpeed = 150f;
            npc.friendly = false;
            npc.noTileCollide = false;
            npc.noGravity = true;
            modNPC.isMinion = true;
            modNPC.minionSlots = 1;
            modNPC.inertia = 30f;
            modNPC.shootSpeed = 10f;
            modNPC.shoot = ProjectileID.ImpFireball;
            Main.npcFrameCount[npc.type] = 8;
            animationType = NPCID.Harpy;
        }

        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.25f;
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;
            npc.spriteDirection = npc.direction;
        }
    }
}
 
Last edited:
Yes. Sure. The purpose here is to summon an npc that acts like a minion. AI is still empty, will do once the summoning issues are dealt with.

The summoning is now happening, but it summons SEVERAL copies of the same NPC and there's an error saying there's an undefined object reference for an object instance. At line 986 which is at ---------player.slotsMinions += modMinion.minionSlots;

I should ask you to ignore anything related to AIs or Sprites right now, the code is not done.

Code:
using ClassOverhaul.UI;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using System;

namespace ClassOverhaul
{
    public class NPCEdits : GlobalNPC
    {
        public override bool InstancePerEntity => true;
        public override bool CloneNewInstances => true;
        public int atkCooldown = 0;
        public int atkSpeed = 30;
        public int defaultAtkSpeed = 30;
        public bool isMinion;
        public int owner;
        public int minionSlots;
        public int minionNum;
        public int minionPos;
        public int numUpdates;
        public int damage;
        public int knockback;
        public int shoot;
        public float shootSpeed;
        public float idleAccel;
        public float spacingMult;
        public float viewDist;
        public float chaseDist;
        public float chaseAccel;
        public float inertia;
        public float shootCool;

        public override void SetDefaults(NPC npc)
        {
            base.SetDefaults(npc);
            if (npc.type == NPCID.BlueJellyfish)
            {
                npc.catchItem = ItemID.BlueJellyfish;
            }
            if (npc.type == NPCID.PinkJellyfish)
            {
                npc.catchItem = ItemID.PinkJellyfish;
            }
            if (npc.type == NPCID.GreenJellyfish)
            {
                npc.catchItem = ItemID.GreenJellyfish;
            }
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            if (modNPC.isMinion == true)
            {
                npc.aiStyle = 0;
                npc.noTileCollide = false;
                npc.noGravity = true;
            }
        }
        public override void AI(NPC npc)
        {
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            if (modNPC.atkCooldown > 0) atkCooldown -= 1;
            if (modNPC.atkCooldown < 0) atkCooldown = 0;
            if (isMinion == true)
            {
                Check(npc);
                base.AI(npc);
                numUpdates++;
            }
            else
            {
                base.AI(npc);
            }
        }

        public override void OnHitPlayer(NPC npc, Player target, int damage, bool crit)
        {
            base.OnHitPlayer(npc, target, damage, crit);
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            modNPC.atkCooldown = modNPC.atkSpeed;
        }

        public override void ResetEffects(NPC npc)
        {
            base.ResetEffects(npc);
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            modNPC.atkSpeed = modNPC.defaultAtkSpeed;
        }

        public override bool CheckDead(NPC npc)
        {
            if (base.CheckDead(npc) && npc.type == NPCID.WallofFlesh)
            {
                PlayerEdits modPlayer = Main.player[Main.myPlayer].GetModPlayer<PlayerEdits>();
                modPlayer.defeatedWoF = true;
                modPlayer.immune = true;
                JobSelection.visible = true;
            }
            return base.CheckDead(npc);
        }

        public void Check(NPC npc)
        {
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            Player player = Main.player[modNPC.owner];
            PlayerEdits modPlayer = player.GetModPlayer<PlayerEdits>();
            if (player.dead)
            {
                modPlayer.Imp = false;
            }
        }

        public override bool CanHitPlayer(NPC npc, Player target, ref int cooldownSlot)
        {
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            if (Main.player[modNPC.owner] == target)
            {
                return false;
            } else
            {
                return base.CanHitPlayer(npc, target, ref cooldownSlot);
            }
        }
    }
}

Code:
        public override bool UseItem(Item item, Player player)
        {
            ItemEdits modItem = item.GetGlobalItem<ItemEdits>();
            if (modItem.hasSummon == true)
            {
                SummonMinion(item, player);
                return true;
            }
            return base.UseItem(item, player);

Code:
 public void SummonMinion(Item item, Player player)
        {
            ItemEdits modItem = item.GetGlobalItem<ItemEdits>();
            int id = NPC.NewNPC((int)player.Center.X, (int)player.Center.Y, modItem.summonNPC);
            NPC minion = Main.npc[id];
            NPCEdits modMinion = minion.GetGlobalNPC<NPCEdits>();
            modMinion.owner = Main.myPlayer;
            modMinion.minionPos = player.numMinions;
            if ((modMinion.minionSlots + player.slotsMinions) > player.maxMinions)
            {
                minion.life = 0;
            }
            else
            {
                player.numMinions++;
                player.slotsMinions += modMinion.minionSlots; //error here
                PlayerEdits modPlayer = player.GetModPlayer<PlayerEdits>();
                modPlayer.playerOwnedMinions.Add(minion);
            }
        }

Edit:
NPC being tested with:

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;

namespace ClassOverhaul.Minions
{
    public class Imp : ModNPC
    {
        public override void SetDefaults()
        {
            base.SetDefaults();
            NPCEdits modNPC = npc.GetGlobalNPC<NPCEdits>();
            npc.width = 32;
            npc.height = 32;
            npc.lifeMax = 300;
            npc.life = 300;
            npc.stepSpeed = 150f;
            npc.friendly = false;
            npc.noTileCollide = false;
            npc.noGravity = true;
            modNPC.isMinion = true;
            modNPC.minionSlots = 1;
            modNPC.inertia = 30f;
            modNPC.shootSpeed = 10f;
            modNPC.shoot = ProjectileID.ImpFireball;
            Main.npcFrameCount[npc.type] = 8;
            animationType = NPCID.Harpy;
        }

        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.25f;
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;
            npc.spriteDirection = npc.direction;
        }
    }
}
I can't really figure out why that code would cause a NullReferenceException, so I'm thinking that's not really the line the error occurs (formatting sometimes messes up the error line). The nearest line that I think could be the culprit is [modPlayer.playerOwnedMinions.Add(minion);] if you haven't created a List instance yet.

If that doesn't appear to be the problem, can you make a screenshot of the exact error and stack trace? And can you also tell me exactly when this error occurs?
 
I can't really figure out why that code would cause a NullReferenceException, so I'm thinking that's not really the line the error occurs (formatting sometimes messes up the error line). The nearest line that I think could be the culprit is [modPlayer.playerOwnedMinions.Add(minion);] if you haven't created a List instance yet.

If that doesn't appear to be the problem, can you make a screenshot of the exact error and stack trace? And can you also tell me exactly when this error occurs?

Code:
[10:37:54] [1/INFO] [tML]: Starting tModLoader v0.11.4 Windows client
[10:37:54] [1/INFO] [tML]: Running on NetFramework 4.7.2
[10:37:54] [1/INFO] [tML]: Executable: C:\Program Files (x86)\Steam\steamapps\common\Terraria\Terraria_tModLoader.exe
[10:37:54] [1/INFO] [tML]: Working Directory: C:\Program Files (x86)\Steam\steamapps\common\Terraria
[10:37:54] [1/INFO] [tML]: Launch Parameters:
[10:37:54] [1/INFO] [tML]: Developer mode enabled
[10:37:54] [1/DEBUG] [tML]: Assembly Resolve:  -> MonoMod.RuntimeDetour, Version=19.5.19.1, Culture=neutral, PublicKeyToken=null
[10:37:54] [1/DEBUG] [tML]: Assembly Resolve: MonoMod.RuntimeDetour, Version=19.5.19.1, Culture=neutral, PublicKeyToken=null -> MonoMod.Utils, Version=19.5.19.1, Culture=neutral, PublicKeyToken=null
[10:37:54] [1/DEBUG] [tML]: Assembly Resolve: MonoMod.Utils, Version=19.5.19.1, Culture=neutral, PublicKeyToken=null -> Mono.Cecil, Version=0.10.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e
[10:37:54] [1/DEBUG] [tML]: Assembly Resolve:  -> Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
[10:37:55] [1/DEBUG] [tML]: Assembly Resolve:  -> Steamworks.NET, Version=9.1.0.0, Culture=neutral, PublicKeyToken=null
[10:37:57] [1/DEBUG] [tML]: Assembly Resolve:  -> Ionic.Zip.Reduced, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c
[10:37:57] [1/DEBUG] [Terraria]: Graphics Device: Radeon RX 570 Series {Width:1360 Height:768 Format:Color AspectRatio:1.770833}
[10:37:57] [1/DEBUG] [Terraria]: Device Reset, Profile: Reach -> HiDef, Width: 800, Height: 480, Fullscreen: False, Display: \\.\DISPLAY1
[10:38:00] [1/DEBUG] [Terraria]: Device Reset, Profile: HiDef, Width: 800 -> 1360, Height: 480 -> 705, Fullscreen: False, Display: \\.\DISPLAY1
[10:38:06] [7/DEBUG] [tML]: Assembly Resolve:  -> MP3Sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
[10:38:06] [7/DEBUG] [tML]: Assembly Resolve:  -> NVorbis, Version=0.8.4.0, Culture=neutral, PublicKeyToken=null
[10:38:07] [7/DEBUG] [tML]: Assembly Resolve:  -> Mono.Cecil.Mdb, Version=0.10.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e
[10:38:07] [7/DEBUG] [tML]: Assembly Resolve:  -> Mono.Cecil.Pdb, Version=0.10.3.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e
[10:38:08] [7/INFO] [Terraria]: JIT loading finished
[10:38:08] [8/INFO] [tML]: Finding Mods...
[10:38:08] [8/INFO] [tML]: Sandboxing: CheatSheet
[10:38:08] [8/INFO] [tML]: Sandboxing: ClassOverhaul
[10:38:08] [8/INFO] [tML]: Instantiating Mods...
[10:38:08] [8/INFO] [tML]: Initializing: ModLoader v0.11.4
[10:38:09] [8/INFO] [tML]: Initializing: CheatSheet v0.5.0.2
[10:38:09] [8/INFO] [tML]: Initializing: ClassOverhaul v0.4.0
[10:38:09] [8/INFO] [tML]: Setting up...
[10:38:09] [8/INFO] [tML]: Loading: ModLoader v0.11.4
[10:38:09] [8/INFO] [tML]: Loading: CheatSheet v0.5.0.2
[10:38:09] [8/INFO] [tML]: Loading: ClassOverhaul v0.4.0
[10:38:09] [8/INFO] [tML]: Adding Recipes...
[10:38:37] [1/DEBUG] [Terraria]: Device Reset, Profile: HiDef, Width: 1360, Height: 705, Fullscreen: False, Display: \\.\DISPLAY1
[10:39:21] [1/DEBUG] [Terraria]: Device Reset, Profile: HiDef, Width: 1360, Height: 705, Fullscreen: False, Display: \\.\DISPLAY1
[10:39:23] [1/DEBUG] [Terraria]: Device Reset, Profile: HiDef, Width: 1360, Height: 705, Fullscreen: False, Display: \\.\DISPLAY1
[10:40:41] [1/DEBUG] [Terraria]: Device Reset, Profile: HiDef, Width: 1360, Height: 705, Fullscreen: False, Display: \\.\DISPLAY1
[10:40:43] [11/INFO] [tML]: Reading properties: ClassOverhaul
[10:40:43] [11/INFO] [tML]: Building: ClassOverhaul
[10:40:43] [11/INFO] [tML]: Compiling ClassOverhaul.XNA.dll
[10:40:43] [11/DEBUG] [tML]: Assembly Resolve: RoslynWrapper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null -> System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[10:40:43] [11/DEBUG] [tML]: Assembly Resolve: RoslynWrapper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null -> Microsoft.CodeAnalysis, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
[10:40:44] [11/DEBUG] [tML]: Assembly Resolve: Microsoft.CodeAnalysis, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 -> System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[10:40:44] [11/DEBUG] [tML]: Assembly Resolve: RoslynWrapper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null -> Microsoft.CodeAnalysis.CSharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
[10:40:44] [11/DEBUG] [tML]: Assembly Resolve: Microsoft.CodeAnalysis.CSharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 -> Microsoft.CodeAnalysis, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
[10:40:44] [11/DEBUG] [tML]: Assembly Resolve: Microsoft.CodeAnalysis.CSharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 -> System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[10:40:44] [11/DEBUG] [tML]: Assembly Resolve: Microsoft.CodeAnalysis.CSharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 -> System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[10:40:44] [11/DEBUG] [tML]: Assembly Resolve: Microsoft.CodeAnalysis, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 -> System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[10:40:44] [11/DEBUG] [tML]: Assembly Resolve: System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a -> System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
[10:40:47] [11/WARN] [tML]: Silently Caught Exception:
System.DllNotFoundException: Não é possível carregar a DLL 'Microsoft.DiaSymReader.Native.x86.dll': Não foi possível encontrar o módulo especificado. (Exceção de HRESULT: 0x8007007E)
   em Microsoft.DiaSymReader.SymUnmanagedFactory.CreateSymWriter32(Guid& id, Object& symWriter)
   em Microsoft.DiaSymReader.SymUnmanagedFactory.CreateObject(Boolean createReader, Boolean useAlternativeLoadPath, Boolean useComRegistry, String& moduleName, Exception& loadException)
   em Microsoft.DiaSymReader.SymUnmanagedWriterFactory.CreateWriter(ISymWriterMetadataProvider metadataProvider, SymUnmanagedWriterCreationOptions options)
   em Microsoft.Cci.PdbWriter.SetMetadataEmitter(MetadataWriter metadataWriter)
   em Microsoft.Cci.PeWriter.WritePeToStream(EmitContext context, CommonMessageProvider messageProvider, Func`1 getPeStream, Func`1 getPortablePdbStreamOpt, PdbWriter nativePdbWriterOpt, String pdbPathOpt, Boolean metadataOnly, Boolean isDeterministic, Boolean emitTestCoverageData, Nullable`1 privateKeyOpt, CancellationToken cancellationToken)
   em Microsoft.CodeAnalysis.Compilation.SerializePeToStream(CommonPEModuleBuilder moduleBeingBuilt, DiagnosticBag metadataDiagnostics, CommonMessageProvider messageProvider, Func`1 getPeStream, Func`1 getMetadataPeStreamOpt, Func`1 getPortablePdbStreamOpt, PdbWriter nativePdbWriterOpt, String pdbPathOpt, Boolean metadataOnly, Boolean includePrivateMembers, Boolean isDeterministic, Boolean emitTestCoverageData, Nullable`1 privateKeyOpt, CancellationToken cancellationToken)
   em Microsoft.CodeAnalysis.Compilation.SerializeToPeStream(CommonPEModuleBuilder moduleBeingBuilt, EmitStreamProvider peStreamProvider, EmitStreamProvider metadataPEStreamProvider, EmitStreamProvider pdbStreamProvider, Func`2 testSymWriterFactory, DiagnosticBag diagnostics, Boolean metadataOnly, Boolean includePrivateMembers, Boolean emitTestCoverageData, String pePdbFilePath, Nullable`1 privateKeyOpt, CancellationToken cancellationToken)
   em Microsoft.CodeAnalysis.Compilation.Emit(Stream peStream, Stream metadataPEStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, CompilationTestData testData, CancellationToken cancellationToken)
   em Microsoft.CodeAnalysis.Compilation.Emit(Stream peStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, Stream metadataPEStream, CancellationToken cancellationToken)
   em Terraria.ModLoader.RoslynWrapper.Compile(String name, String outputPath, String[] references, String[] files, String[] preprocessorSymbols, Boolean includePdb, Boolean allowUnsafe)
   em System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   em System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   em System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   em Terraria.ModLoader.Core.ModCompile.RoslynCompile(String name, String outputPath, String[] references, String[] files, String[] preprocessorSymbols, Boolean includePdb, Boolean allowUnsafe)
   em Terraria.ModLoader.Core.ModCompile.CompileMod(BuildingMod mod, String outputPath, List`1& refMods, Boolean xna)
   em Terraria.ModLoader.Core.ModCompile.BuildModForPlatform(BuildingMod mod, List`1& refMods, Boolean xna)
   em Terraria.ModLoader.Core.ModCompile.Build(BuildingMod mod)
   em Terraria.ModLoader.Core.ModCompile.Build(String modFolder)
   em Terraria.ModLoader.UI.DownloadManager.UIBuildModProgress.<>c__DisplayClass5_0.<Build>b__0(ModCompile mc)
   em Terraria.ModLoader.UI.DownloadManager.UIBuildModProgress.BuildMod(Action`1 buildAction, Boolean reload)
   em Terraria.ModLoader.UI.DownloadManager.UIBuildModProgress.<>c__DisplayClass7_0.<Build>b__0()
   em System.Threading.Tasks.Task.InnerInvoke()
   em System.Threading.Tasks.Task.Execute()
   em System.Threading.Tasks.Task.ExecutionContextCallback(Object obj)
   em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   em System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   em System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   em System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   em System.Threading.ThreadPoolWorkQueue.Dispatch()
   em System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

[10:40:47] [11/DEBUG] [tML]: Assembly Resolve:  -> Microsoft.CodeAnalysis.CSharp.resources, Version=2.10.0.0, Culture=pt-BR, PublicKeyToken=31bf3856ad364e35
[10:40:47] [11/DEBUG] [tML]: Assembly Resolve: Microsoft.CodeAnalysis.CSharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 -> Microsoft.CodeAnalysis.CSharp.resources, Version=2.10.0.0, Culture=pt-BR, PublicKeyToken=31bf3856ad364e35
[10:40:47] [11/DEBUG] [tML]: Assembly Resolve:  -> Microsoft.CodeAnalysis.CSharp.resources, Version=2.10.0.0, Culture=pt, PublicKeyToken=31bf3856ad364e35
[10:40:47] [11/DEBUG] [tML]: Assembly Resolve: Microsoft.CodeAnalysis.CSharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 -> Microsoft.CodeAnalysis.CSharp.resources, Version=2.10.0.0, Culture=pt, PublicKeyToken=31bf3856ad364e35
[10:40:47] [11/INFO] [tML]: Compilation finished with 0 errors and 3 warnings
[10:40:47] [11/WARN] [tML]: C:\Users\davio\OneDrive\Documentos\My Games\Terraria\ModLoader\Mod Sources\ClassOverhaul\ItemEdits.cs(892,29) : warning CS0672: Member 'ItemEdits.GetWeaponDamage(Item, Player, ref int)' overrides obsolete member 'GlobalItem.GetWeaponDamage(Item, Player, ref int)'. Add the Obsolete attribute to 'ItemEdits.GetWeaponDamage(Item, Player, ref int)'.
[10:40:47] [11/WARN] [tML]: C:\Users\davio\OneDrive\Documentos\My Games\Terraria\ModLoader\Mod Sources\ClassOverhaul\CustomPrefixes.cs(16,21) : warning CS0649: Field 'RangedManaPrefix.rarity' is never assigned to, and will always have its default value 0
[10:40:47] [11/WARN] [tML]: C:\Users\davio\OneDrive\Documentos\My Games\Terraria\ModLoader\Mod Sources\ClassOverhaul\PlayerEdits.cs(21,25) : warning CS0649: Field 'PlayerEdits.playerOwnedMinions' is never assigned to, and will always have its default value null
[10:40:48] [11/INFO] [tML]: Compiling ClassOverhaul.FNA.dll
[10:40:48] [11/INFO] [tML]: Compilation finished with 0 errors and 3 warnings
[10:40:48] [11/WARN] [tML]: C:\Users\davio\OneDrive\Documentos\My Games\Terraria\ModLoader\Mod Sources\ClassOverhaul\ItemEdits.cs(892,29) : warning CS0672: Member 'ItemEdits.GetWeaponDamage(Item, Player, ref int)' overrides obsolete member 'GlobalItem.GetWeaponDamage(Item, Player, ref int)'. Add the Obsolete attribute to 'ItemEdits.GetWeaponDamage(Item, Player, ref int)'.
[10:40:48] [11/WARN] [tML]: C:\Users\davio\OneDrive\Documentos\My Games\Terraria\ModLoader\Mod Sources\ClassOverhaul\CustomPrefixes.cs(16,21) : warning CS0649: Field 'RangedManaPrefix.rarity' is never assigned to, and will always have its default value 0
[10:40:48] [11/WARN] [tML]: C:\Users\davio\OneDrive\Documentos\My Games\Terraria\ModLoader\Mod Sources\ClassOverhaul\PlayerEdits.cs(21,25) : warning CS0649: Field 'PlayerEdits.playerOwnedMinions' is never assigned to, and will always have its default value null
[10:40:48] [11/INFO] [tML]: Packaging: ClassOverhaul
[10:40:48] [11/INFO] [tML]: Enabling Mod: ClassOverhaul
[10:40:48] [1/INFO] [tML]: Unloading mods
[10:40:48] [1/INFO] [tML]: Unloading: Athos's Class Overhaul
[10:40:48] [1/INFO] [tML]: Unloading: Cheat Sheet
[10:40:48] [1/INFO] [tML]: Unloading: tModLoader
[10:40:49] [14/INFO] [tML]: Finding Mods...
[10:40:49] [14/INFO] [tML]: Sandboxing: CheatSheet
[10:40:49] [14/INFO] [tML]: Sandboxing: ClassOverhaul
[10:40:49] [14/INFO] [tML]: Instantiating Mods...
[10:40:49] [14/INFO] [tML]: Initializing: ModLoader v0.11.4
[10:40:50] [14/INFO] [tML]: Initializing: CheatSheet v0.5.0.2
[10:40:50] [14/INFO] [tML]: Initializing: ClassOverhaul v0.4.0
[10:40:50] [14/INFO] [tML]: Setting up...
[10:40:50] [14/INFO] [tML]: Loading: ModLoader v0.11.4
[10:40:50] [14/INFO] [tML]: Loading: CheatSheet v0.5.0.2
[10:40:50] [14/INFO] [tML]: Loading: ClassOverhaul v0.4.0
[10:40:50] [14/INFO] [tML]: Adding Recipes...
[10:41:01] [15/INFO] [Terraria]: Loading World: a, IsCloud=False
[10:41:01] [15/INFO] [StatusText]: Redefinindo objetos do jogo
[10:41:02] [15/INFO] [StatusText]: Carregando dados do mundo
[10:41:02] [15/INFO] [StatusText]: Acomodando líquidos
[10:41:03] [15/INFO] [StatusText]: Carregando os dados do mapa
[10:41:03] [15/INFO] [StatusText]: Desenhando o mapa
[10:41:03] [1/INFO] [Terraria]: Entering world with player: a, IsCloud=False
[10:41:04] [1/WARN] [tML]: Silently Caught Exception:
System.NullReferenceException: Referência de objeto não definida para uma instância de um objeto.
   em ClassOverhaul.ItemEdits.SummonMinion(Item item, Player player) na ClassOverhaul\ItemEdits.cs:linha 986
   em ClassOverhaul.ItemEdits.UseItem(Item item, Player player) na ClassOverhaul\ItemEdits.cs:linha 965
   em Terraria.ModLoader.ItemLoader.UseItem(Item item, Player player)
   em Terraria.Player.ItemCheck(Int32 i)
   em Terraria.Player.ItemCheckWrapped(Int32 i)
   em Terraria.Player.Update(Int32 i)
   em Terraria.Main.DoUpdate(GameTime gameTime)
   em Terraria.Main.Update(GameTime gameTime)
   em Microsoft.Xna.Framework.Game.Tick()
   em Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
   em Microsoft.Xna.Framework.GameHost.OnIdle()
   em Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
   em Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
   em System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
   em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   em System.Windows.Forms.Application.Run(Form mainForm)
   em Microsoft.Xna.Framework.WindowsGameHost.Run()
   em Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
   em Terraria.Program.LaunchGame_()
   em Terraria.Program.LaunchGame(String[] args, Boolean monoArgs)
   em Terraria.WindowsLaunch.Main(String[] args)

[10:41:14] [12/INFO] [StatusText]: Salvando os dados do mapa
[10:41:14] [12/INFO] [StatusText]: Salvando dados do mundo
[10:41:14] [12/INFO] [StatusText]: Validando o mundo salvo

By the end, line 986 is: player.slotsMinions += modMinion.minionSlots;
and line 965 is return true;
965 is at UseItem
986 is at SummonMinion

The error occurs when I use the item. It summons several copies of the NPC and notify me about the error on by the chat area. And no, I do have declared the List: public List<NPC> playerOwnedMinions; at my ModPlayer.
 
Unfortunately I really can't figure out why that line would throw a NullReferenceException, since you're using the same references just a few lines earlier without any problems. I'm afraid I can't help you any further, but maybe the people in the tModLoader discord can help you better than I can.
 
Unfortunately I really can't figure out why that line would throw a NullReferenceException, since you're using the same references just a few lines earlier without any problems. I'm afraid I can't help you any further, but maybe the people in the tModLoader discord can help you better than I can.
Thank you. I've figured it out the issue with multiple npcs spawning... and the NullReference vanished after that.
 
Back
Top Bottom