Behavior Designer - Referencing Prefabs in Tasks

I am confused about some of the default tasks, prefabs and gameobjects. I was hoping someone could provide a little guidance on this.

I have a prefab that is referenced in multiple scenes and I want to associate a tree with it so that the same behavior is consistent in each scene. So on my prefab I create a behavior tree and I set up the tasks. Everything works great until I want to use the GetFieldValue, SendMessage and Invoke tasks.

Note: gameobjects are created during runtime so I really want to use prefabs to solve this and not gameobjects in each of the scenes.

I have tried several approaches to try to get this to work. Here is one of my attempts.

With GetFieldValue, I drag the prefab from my project view into the task inspector and I am able to see a list of components and select a field. Cool. And when running the project the correct gameobject from the scene is referenced and the field value is retrieved without error.

Note: I was wrong. GetFieldValue works but not how I want it to. I want it to reflect the gameobject associated with the prefab in the scene. At runtime it continually returns the prefab’s initial value.

With Invoke, if I drag a prefab from my project view into the task inspector I am NOT able to see a list of components in order to select a method. I am only able to view the components if I select a gameobject from the scene.

With SendMessage, I am able to select my prefab but at runtime I get a “SendMessage mymethod has no receiver!”

Any advice appreciated.

For future questions, can you please post in the Behavior Designer thread or the Opsive forums? This will allow me to see your question a lot quicker.

I was able to successfully use the reflection tasks by doing:

  1. Add a behavior tree to a GameObject within the scene
  2. Add the reflection task
  3. Create a prefab from that GameObject

The reflection task correctly executed when I ran the tree after instantiating the prefab. As you mentioned, if you create the prefab ahead of time and then try to use the reflection tasks it cannot find the component. I have a fix for this - just send me an email or PM with your invoice number and I’ll send you a new version.

1 Like

will post in the correct thread in the future. I really like the designer; I just think I am approaching things in a way that things get confused (unhooked). cheers