Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Noob questions about performance

$
0
0
This question are so basic that I feel bad opening a topic for it, whish there was a chat instead, maybe I should propose that later Anyway, here's my code: // Called every frame void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); OpenDoor(DeltaTime); } void UOpenDoor::OpenDoor(float DeltaTime) { float RotationAmmount = RotationSpeed * DeltaTime; if (!FMath::IsNearlyEqual(CurrentYaw, OpenYaw, RotationAmmount)) { float NewYaw = CurrentYaw - RotationAmmount; CurrentYaw += NewYaw < -180 ? NewYaw + 360 : -RotationAmmount; GetOwner()->SetActorRotation(FRotator(0.f, CurrentYaw, 0.f)); } } My question pertains the OpenDoor() function called every frame. As you see I'm creating 2 floats inside of it every frame(let's assume this door keep opening forever), is this a good practice or since it happens every frame I should rather have those 2 floats as persistent private variable of my class? Between the two methods, there can be any noticeable performance difference with many assets that create 2 floats at every frame? My second question is similar to the first, but is about the GetOwner() function called every frame. Should I rather store a Owner pointer in my class? Can this become noticeably expensive if I have many objects calling GetOwner function at every frame?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>