{"record":{"id":"a99bdeebc323fdd2","repo":"EllanJiang/GameFramework","slug":"target-0-is-invalid","errorCode":null,"errorMessage":"Target '{0}' is invalid.","messagePattern":"Target '(.+?)' is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/ObjectPool/ObjectBase.cs","lineNumber":165,"sourceCode":"        /// <param name=\"target\">对象。</param>\n        /// <param name=\"priority\">对象的优先级。</param>\n        protected void Initialize(string name, object target, int priority)\n        {\n            Initialize(name, target, false, priority);\n        }\n\n        /// <summary>\n        /// 初始化对象基类。\n        /// </summary>\n        /// <param name=\"name\">对象名称。</param>\n        /// <param name=\"target\">对象。</param>\n        /// <param name=\"locked\">对象是否被加锁。</param>\n        /// <param name=\"priority\">对象的优先级。</param>\n        protected void Initialize(string name, object target, bool locked, int priority)\n        {\n            if (target == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Target '{0}' is invalid.\", name));\n            }\n\n            m_Name = name ?? string.Empty;\n            m_Target = target;\n            m_Locked = locked;\n            m_Priority = priority;\n            m_LastUseTime = DateTime.UtcNow;\n        }\n\n        /// <summary>\n        /// 清理对象基类。\n        /// </summary>\n        public virtual void Clear()\n        {\n            m_Name = null;\n            m_Target = null;\n            m_Locked = false;\n            m_Priority = 0;","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/ObjectPool/ObjectBase.cs#L147-L183","documentation":"ObjectBase.Initialize is the shared setup for pooled objects and requires a non-null Target — the actual game resource (e.g. an asset, entity, or GameObject) the wrapper represents. A null target makes the pool entry unusable, so it throws with the object's name in the message. Subclass constructors funnel through Initialize, so the throw surfaces when constructing any invalid ObjectBase.","triggerScenarios":"Constructing an ObjectBase subclass (e.g. FooObject : ObjectBase) with null passed as target, commonly when a resource load returned null before being wrapped.","commonSituations":"AssetBundle/Resources.Load returning null (missing asset, wrong path) and the result being wrapped unconditionally; async load completing with a null handle result; passing an uninitialized field as target.","solutions":["Ensure the target object is loaded and non-null before constructing/wrapping it","Null-check the load result and handle the load failure separately instead of passing null to the object pool","Verify resource paths and that the asset exists in the build"],"exampleFix":"// before\nvar obj = new MyObject(\"enemy\", loadedAsset, false, 0); // loadedAsset is null\n// after\nif (loadedAsset == null) { throw new InvalidOperationException(\"Failed to load asset 'enemy'.\"); }\nvar obj = new MyObject(\"enemy\", loadedAsset, false, 0);","handlingStrategy":"validation","validationCode":"if (target == null) { Log.Error(\"Cannot pool '{0}': target is null (load failed?)\", name); return; }\nvar obj = new MyObject(name, target, locked, priority);","typeGuard":"bool IsValidTarget(object t) => t != null;","tryCatchPattern":"try { var obj = new MyObject(name, target, locked, priority); }\ncatch (GameFrameworkException ex) { Log.Error(\"Invalid pooled object target: {0}\", ex.Message); }","preventionTips":["Null-check all resource load results before wrapping","Fail the load path distinctly from the pooling path","Assert assets exist in build settings"],"tags":["objectpool","null-argument","gameframework"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}