TankAimingCompRef : Why is it better ? (and works) ? not clear to me

Ok so the idea is using GetComponentByClassName on TankPlayerController work better than using directly the property TankAimingComponentdirectly, as they both point to same reference and triggered the same (event Begin Play) ?

I feel stupid there. If someone could just clear my mind of this particular point I would appreciate.

Cheers

Ok just undestood now !!! :smiley:
In facet when the component has been added, the tank reference to aim steel need to be set so that’s what the BP -then c+± is doing …

Excuse me brother
could you explain your answer still confusing :slight_smile:

I think it is somewhat like the following:
When we introduced the color change of the crosshair it worked fine, because we had defined, what the TankAimingComponent is, in the Tank.h and Tank.cpp

UPROPERTY (BlueprintReadOnly)
UTankAimingComponent* TankAimingComponent = nullptr;

and in the Tank.cpp we assigned the variable TankAimingComponent to the actual component in while constructing it:

TankAimingComponent = CreateDefaultSubobject<UTankAimingComponent>(TEXT("Aiming Component"))

But in the next lectures, during the refactoring, this code got deleted, so there is no definition of the TankAimingComponent inside the Tank.h/Tank.cpp anymore.
That means, if we are still trying to get the TankAimingComponent from the Tank (which we are trying to do at the PlayerController Blueprint by getting the tank and then extracting the variable TankAimingComponent (which now doesn’t exist anymore)) it doesn’t work.

That’s why we need another way of getting the TankAimingComponent, which is looking for all Component of the Tank and then just take the one which is also of the class TankAimingComponent.

For my understanding it has nothing to do with all the timing explanations, but just because the code got deleted during refactoring.

Privacy & Terms