How to assign variables?

nicmar

New member
Hi, i'm watching the video "Behaviour Designer Overview" and BD seems to have to changed since.
I made a variable "target", but I can't assign "Object in Sight", there is no such thing. There is a "Returned object" though, but i can only select something from the scene.
How do I tell it to store the detected object in the variable "target"?

Thanks!

Skärmavbild 2020-06-04 kl. 13.53.12.png
1591271717395.png
 
I don't get "Can See Object" to work at all. See my attached settings.
I have the player assigned both as Target object, and as "Player" tag, and the player has that tag.
The cone of vision shows the player in front of the enemy, but the "Can See Object" node returns failure.

Did I miss any step here?

Please help, I really want to get cool AI things going :D

Skärmavbild 2020-06-04 kl. 15.37.13.pngSkärmavbild 2020-06-04 kl. 15.37.09.pngSkärmavbild 2020-06-04 kl. 15.38.38.png
 
There are two different Can See Object tasks. There is one included with the tutorial resources which is what the video is based off of. The one that you are looking at is from the Movement Pack and contains more options. You can assign shared variables by clicking on the button with the dot to the right of the field. Take a look at this video:


Based on your screenshot it doesn't look like you have the latest version of the Movement Pack. If you update you'll have an option to Draw Debug Ray which will show you the ray that is being used, as well as the color indicates the status:

 
Thanks, I will check that video.
But when I clicked the button you said, i get an error, and i can choose (none) or (dynamic), not from my list of variables. What does this mean?
I will try to update to the latest version though, it was a year since i downloaded it so it's probably very old. :)

Skärmavbild 2020-06-05 kl. 12.02.57.pngSkärmavbild 2020-06-05 kl. 12.03.24.pngSkärmavbild 2020-06-05 kl. 12.02.51.png
 
Aha! That worked! I'm not sure if I chose transform by mistake, or the tutorial for the other version of it had a transform. But at least I could select it now. Thanks!

I added the debug ray, and the ray hits the player. It's red when outside the cone, and yellow inside.
But there is still a red cross on the task, and the player gameobject isn't added in the target variable.

Isn't it suppose to return success when it sees the object, and update the target variable?
 
I nailed it down to this code:
if (IsAncestor(targetObject.transform, hitTransform)) {
// Green line
} else {
// Yellow line, this is what gets triggered.
}

Which in turn runs this:
// Is the hitObject an ancestor of the target?
public static bool IsAncestor(Transform target, Transform hitTransform)
{
return hitTransform.IsChildOf(target) || target.IsChildOf(hitTransform);
}

But they are not ancestors, they are siblings in the scene view... hmm.
 
Hmm, so the current code in MovementUtility requires the hit object to be a child of the transform having the task.
Is this flipped around?

I changed it to
if (!IsAncestor(targetObject.transform, hitTransform)) {

and now it works and sees the object.

But I'm curious if it should care wheter it's a child/parent relationship or not.

Thanks :)
 
@nicmar I think I'm having the same the problem you solved. I'm trying to copy this video as well:
Can you tell me what you did so that you could place the Player gameobject from your Hierarchy into the "Player" variable you made in Behavior Designer? My larger goal is to get Justin's setup where he logs a "Last Position" where the "Player" was last seen.

BT.png
 
Hey, i’m very new to this but it looks like you created the player variable as a Transform, remove it and make it a gameobject insteas and it should work. Thanks for the video, it’s helpful to watch more to learn :)
 
@Justin can you comment on if I should care if it's a child/parent relationship or not and the IsAncestor call, which I had to invert to make it work? Thanks :)
 
The IsAncestor check will ensure that the found object is related to the target object. There was a problem with this within the WithinDistance task but that has been updated on the Asset Store. If you have to negate it can you send a repro scene to support@opsive.com and I'll take a closer look?
 
Thanks, I might have to do that to make sure i can update to future versions without it breaking. :) It will probably take a while, thanks :)
 
Just to confirm, i made a repro scene, and everything worked, so i probably messed something else up. Will try more in my big tree :)
 
Hey again @Justin, I tried it again in my game project, and finally found the problem!
The raycast of the CanSee is hitting itself, thus causing the yellow line. When i changed the offset a little, it worked.

In my repro scene, i didn't have colliders first until i realized that was the issue.
Then I googled, and found this on stackoverflow.
"if you go to Edit -> Project Settings -> Physics2d and Uncheck the box that says "Raycasts Start In Colliders" it solves this issue."

Is that the proper way to solve this, I guess it should be very common with the agent having the CanSee behaviour also have a collider?

Thanks!
 
Hmm, so the current code in MovementUtility requires the hit object to be a child of the transform having the task.
Is this flipped around?

I changed it to
if (!IsAncestor(targetObject.transform, hitTransform)) {

and now it works and sees the object.

But I'm curious if it should care wheter it's a child/parent relationship or not.

Thanks :)
Yes, that's worked for me. Thank you
 
Top