my colour retical doesnt change and i get this error in my log.
Apparantly my tank was being created after the beginplay on tankplayercontroller which meant bp aiming comp could not be set as there was no tank to pull data from. I added a 1 second delay in the beginplay so the tank has enough time to spawn so that the getcontrolledtank now actually returns something. Is this a viable fix? Im not sure what else could be done. I heard ben say we’re gonna be moving it all into c++ anyway.
It only works with a 2 second or more delay. I tried 1 second but its not enough time.
does anyone know why the player tank is taking so long to initialise?
ok i found my issue. i feel stupid. when Ive been testing the game, i have been using similation mode which starts the game but then i have to click possess to spawn in tank. it now works perfect without the delay when possessing tank on game start. this entire post should probably be deleted.
Glad you were able to solve your problem.
Hello Den
In this Lecture Ben said that we can’t set AimingComponent pointer in Tank C++ constructor because AimingComponent is not exist yet (Lecture 172 time 4:30)
But before we start refactoring TankAimingComponet as a SubClass was created in Tank C++ constructor what has changed now?
I could not understand
Now I am in Lecture 177 and have tried to create TankAimingComponent in Tank C++ Constructor again but it was not created
Whereas in old architecture we such way created AimingComponent
Refer to the previous lectures, the aiming component was moved to BP, so it wouldn’t exist on C++ construction yet. (Starting 169)
-
I solved the problem Den as I guess CreateDefaultSubobject() can work in Tank C++ Constructor but FindComponentByClass() can’t because Tank_C constructor runs before Tank_BP and therefor FindComponentByClass() can’t find something.
-
how work FindComponentByClass() function?
we have three inheritor class: Pawn->Tank_C->Tank_BP and how can Pawn with FindComponentByClass() find the AimingComponent in Tank_BP ?
(I mean the Line:
auto AimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>(); )
FindComponentByClass() is a freind function or something like?
- My name is Dan
- FindComponentByClass is a function on AActor, it loops through it’s components and returns the first UActorComponent* of the specified type which must be derived from UActorComponent.
Thank you Dan