SharedVariable mapped to float in Monobehaviour is always zero!!

xinoHITO

New member
Well, title says it all. I have a class called WolfAI that inherits from a class called EnemyBehaviour.
EnemyBehaviour has a DetectionRange property.


Code:
public class EnemyBehaviour : MonoBehaviour, IKnockback
{
    [TitleGroup("ENEMY")]
    [FoldoutGroup("ENEMY/Detection")]
    public bool _showRangeGizmo = false;
    [FoldoutGroup("ENEMY/Detection")]
    public float _detectionRange = 67.0f;
    public float DetectionRange { get { return _detectionRange; } }
    ...
}

When I mapped a SharedVariable in my BehaviourTree to the DetectionRange property it's always zero.

It's weird because when I try my WolfAI class it doesn't work... but if I use my EnemyBehaviour class instead... it works normally.

I recently update Behaviour Designer from 1.6.5 from I think it was 1.6.2. I didn't delete my Behaviour Designer when updating. Is it possible this is the cause?
 
Are you able to reproduce the problem within a fresh project? Updating versions shouldn't have caused it.
 
Ok, I tried and created a fresh new project with only the scripts needed to test my WolfAI and EnemyBehaviour classes.

I imported BehaviourDesigner and the Movement Pack fresh and it seems to work correctly.

I forgot to mention that in my current project I moved Behaviour Designer to another folder to organize my assets. Maybe that's causing the issue. I'll try reinstalling the package and see whether that works.

Also, I separated my project's code into multiple DLL using Unity's Assembly Definition Files. I grouped everything from the Asset Store into a single DLL called Main.dll and another called Main.Editor.dll for everything inside an Editor folder ...everything works and I solved all the dependencies issues... but maybe it's worth mentioning for this.

[UPDATE] I deleted and reinstalled Behaviour Designer and the Movement Pack in their default location... (had to set up a few Assembly Definition but it wasn't a big deal). Unfortunately, the bug persists.

Just a bit more info on the bug... I set the SharedVariable to a hard value of let's say 10. I then try to Map it to a variable in my MonoBehaviour script and when I enter Play Mode it stays with the old value of 10.
 
Last edited:
Oh I found the solution! I turns out I was setting the value of another SharedVariable through code. The issue was that this SharedVariable was also Mapped to a variable ... so this weird loop apparently caused the bug ... I deleted the code that set the value of the SharedVariable and now everything seems to work fine.

[UPDATE] it seems all my enemies bugged out when I reinstalled BD in relation to their sharedVariable....this is a big headache... some enemies don't keep track of their mapped SharedVariables and some other do. Please can you help me with this?

Maybe it has to do with the fact that some enemies modify the SharedVariable in code and in the BehaviourTree ? are you supposed to only modify those in one place?
 
Last edited:
Top