IsaacMulcahy / RPG-AI-SYSTEM-WIKI

A wiki which covers how the RPG-AI-SYSTEM works and how to customize it
5 stars 0 forks source link

Null exception when applying NPC template #10

Open Sanglyon opened 7 months ago

Sanglyon commented 7 months ago

In Unity 2021.3.32f1, in a new project Packages imported: CIVIL-AI, Synthy PolygonFarm

I put a Synthy character in my scene, unpacked the prefab then applied the NPC template to it. A Null exception is raised, pointing to "Resources.Load("System/Objects/AI");" in AIOverviewManager.AddInNPCTemplate()

This is because Resources.Load search in a "Resources" directory which doesn't exist. The RuntimeAnimatorController "AI.controller" is in "Assets/CIVIL-AI-SYSTEM/Animation Controller/Controller", so I fixed the issue by replacing

animator.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController>("System/Objects/AI");

with

animator.runtimeAnimatorController = AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>("Assets/CIVIL-AI-SYSTEM/Animation Controller/Controller/AI.controller");

------------------------------------------------------

Also, I made another change, but it's not technically a bug. Since the Synthy character already has an animator component with an avatar defined, I also replaced

Animator animator = selected.AddComponent<Animator>();

with

Animator animator; if(!selected.TryGetComponent<Animator>(out animator)) { animator = selected.AddComponent<Animator>(); }

IsaacMulcahy commented 7 months ago

Hi Sanglyon,  Any chance you can tell me which version you have downloaded of the tool? You can find this out in the package manager. Also did you import the file using the package manager into your project or did you download it from another and then copied it across?  Thanks, Isaac On Saturday, 20 April 2024 at 23:19:03 BST, Sanglyon @.***> wrote:

In Unity 2021.3.32f1, in a new project Packages imported: CIVIL-AI, Synthy PolygonFarm

I put a Synthy character in my scene, unpacked the prefab then applied the NPC template to it. A Null exception is raised, pointing to "Resources.Load("System/Objects/AI");" in AIOverviewManager.AddInNPCTemplate()

This is because Resources.Load search in a "Resources" directory which doesn't exist. The RuntimeAnimatorController "AI.controller" is in "Assets/CIVIL-AI-SYSTEM/Animation Controller/Controller", so I fixed the issue by replacing

animator.runtimeAnimatorController = Resources.Load("System/Objects/AI");

with

animator.runtimeAnimatorController = AssetDatabase.LoadAssetAtPath("Assets/CIVIL-AI-SYSTEM/Animation Controller/Controller/AI.controller");


Also, I made another change, but it's not technically a bug. Since the Synthy character already has an animator component with an avatar defined, I also replaced

Animator animator = selected.AddComponent();

with

Animator animator; if(!selected.TryGetComponent(out animator)) { animator = selected.AddComponent(); }

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>