- Home /
Nested Prefab Issue
Hi All,
I've been searching on here for help on my issue, but I can't seem to find anything like I have built. I am thinking someone else has run into this problem before, and can point me in the right direction.
Here is the issue:
I have an NPC prefab, I then place a script on it with a public array of transforms. I place another script on it, that when start is called on the first script, it loads the tags and transforms into a dictionary on the second script.
This works fine, and if I only have one NPC, everything is peachy. If I drop these same scripts on another NPC GameObject with the same Transforms in it's Transform array, then I run into problems when I hit play.
The message I get is that the dictionary already has a key of the same name. Which means that the script that controls the dictionary is being shared between the two game objects it's been placed on.
How do you get around that?
Let me know if I didn't explain it well.
Thanks, Matt
Hi $$anonymous$$att,
$$anonymous$$aybe it would be helpful to post your scripts together with this question.
Here is my Prefab that I can drop on a game object.
Looking at the Entity AI script, it has an Array of tasks. These are themselves prefabs. A method to load the tasks in the Task Processor script is called from the Entity AI script. This load tasks method takes the array as a parameter, and puts the array contents into a dictionary.
$$anonymous$$y problem is that the dictionary seems to be shared between any game object I drop this prefab on.
Thanks, $$anonymous$$att
Looks like I fixed part of the issue. I created a child object and dropped the TaskProcessor script on it. Now I don't get any problems with the dictionary in the TaskProcessor. However I am still having issues with the actions under my tasks which were set up similarly.
I'll have to mess with it and move things around until they aren't conflicting.
So a quick overview of what I am trying to accomplish.
I'm trying to build an easy way to create tasks for an AI entity. If everything is pre-made, all the actions are atomic, then you can drag and drop the actions on a new task, configure them, then you have a new task for your Entity to perform.
The problem I am still having is that the entities are sharing the tasks. So any randomness in the tasks will be the same for each entity. I can make the tasks and actions configurable, but I can't expect them to be treated differently for each entity.
Do I need to design the tasks and actions to act as singletons? They seem to be acting that way now.
How do you not share state between prefabs of the same type? How do I have all my skeletons act differently? Drive the randomness from somewhere else?
Thanks, $$anonymous$$att
I'm not sure if it would be different if these entities were being spawned vs. dragging an AI prefab controller onto an entity in the scene. Right now I am just dragging the AI prefab on 2 different entities in the scene.