AIPath : IAstarAI property bug (?)


#1

Hi,

In my project I’m trying to control external object (basically parent object) using pathfinder logic. To do that I’ve extended AIPath and override a few functions, for example FindComponents(). The problem that my parent object contain speed settings (used by another scripts) and there is beautiful possibility to provide this numbers to the AIPath script:

float IAstarAI.maxSpeed { 
    get { return _actor.MaxSpeed; } 
    set { _actor.MaxSpeed = value; } 
}

The only problem - AIPath script is not using this value :slight_smile: Instead it’s using raw value from AIBase. Is that a bug? I mean I’ve changed AIPath script a bit to support needed functionality, but maybe there is an another way to do that?

For example my change in AIPath.cs:289

// If negative, calculate the acceleration from the max speed
if (currentAcceleration < 0) currentAcceleration *= -((IAstarAI) this).maxSpeed;

#2

Hi

Yeah, I use the IAstarAI script more to expose the values, the script doesn’t use them itself usually. Perhaps I should change it.


#3

Thank you for reply, Aron.

I thought that this isn’t a bug, but a part of design, but actually didn’t understand why to not use property instead of raw value. Anyway it’s not critical, but it might be a good point to extend AIPath instead of writing a custom one.


#4

It does have some impact on performance. Mono is really bad at generating good code and will usually not inline the property.


#5

Didn’t know that, thank you for explanation!


#6

Hi @aron_granberg! Thank you again for the lib, it’s working amazing.

The question is regarding the “issue”. Will the approach change in the future or I have to consider about some workaround?


#7

Hi

I do not have any current plans to change the approach. If necessary you can easily change the implementation locally though.

If _actor.MaxSpeed is a property you could also use this workaround:

float MaxSpeed {
    get { ... }
    set {
        ...
        ai.maxSpeed = value;
    }
}

#8

I’ve changed implementation locally, but this is kinda bad approach. Will think about the workaround, but the problem is that AIPath is optional object in the actor. And the idea was just to use value from it, instead syncronizing values between two separated objects.