A little extra after the lesson + some questions

So I finally was able to make my way to the end of the Escape the Room and I think it left me with a great understanding of the Unreal Engine itself.

Here’s a link to a video of what I decided to add on after the lesson.

Basically it’s a Lamp Pull function. I ended up liking the idea of it being a false positive so right now it doesn’t do anything, however I have some ideas on how I would hook it up to the Open/Close door functions

It took a bit of work to get everything working as I had quite a few false starts in how I wanted to go about it.

In the end, it settles with converting the lamp/light into a blueprint actor and wired up a blueprint event for rotating it, delaying, and then rotating it back.

From there I updated the Grabber.cpp to include an Interact button, and slightly modified the linetrace to search for a WorldDynamic type collision (I tried converting the blueprint object simulate physics and ho boy did that cause some hilarious bugs, such as the lamp rocketing back and forth across the room for 8 seconds)

Summary

void UGrabber::Interact() {
/// LINE TRACE and see if we reach any actors with physics body collision channel set
auto HitResult = GetFirstCollisionInReach();
auto ComponentToGrab = HitResult.GetComponent(); // gets the mesh in our case
auto ActorHit = HitResult.GetActor();

if (ActorHit) {
	UE_LOG(LogTemp, Error, TEXT("I have interacted with %s"),
		*ActorHit->GetName()
	);

	PullLamp.Broadcast();

}
else {
	UE_LOG(LogTemp, Error, TEXT("ActorHit is somehow a nullptr"));
}

}

This also required a new line trace function for the specific collision channel

Summary

const FHitResult UGrabber::GetFirstCollisionInReach()
{
/// Setup query parameters
FHitResult HitResult;
FCollisionQueryParams traceParameters(FName(TEXT("")), false, GetOwner());
/// Line-trace (Ray-cast) out to reach distance
GetWorld()->LineTraceSingleByObjectType(
OUT HitResult,
getReachLineStart(),
getReachLineEnd(),
FCollisionObjectQueryParams(ECollisionChannel::ECC_WorldDynamic),
traceParameters
);
return HitResult;
};

Finally it required running an event on the default pawn object itself to trigger the raycast hit

As for making the door open when pulled, I’m pretty sure in the Default Pawn blueprint, after the Pull Lamp function I could create another “Cast To” object and run the Open Door blueprint functions as well.

With that however, I do have a few questions. While i’m happy I got it working, it’s not quite how I wanted to get it working.

In my mind the idea was to create a collision detection class that would be a component of the lamp blueprint that monitored for “being hit by a ray cast” and then from there trigger the rotation in blue print itself with a blueprint broadcast in said custom class. Unfortunately I just could not figure out how to monitor for that type of thing, especially only when the Interact “E” key was pressed. Does anyone have an idea as to how I would achieve that. I feel like doing that would be more reusable as I could place it on any lamp as well as other objects later if I wanted them to do different things, not to mention mirror the work we did with open door and grabber a bit more closely as opposed to putting a lot of the work into blueprint (which I don’t mind, I just wanted to stick to the types of solutions we were already doing within the course).

I tried setting up an input component and and then searching for overlapping actors, but since it’s not a pawn, the input component couldn’t get a physics handle or check for input. The overlapping actors also didn’t seem to work, but I think I could have gotten that if I kept going, but even if I did, i didn’t know how I would search for a “raycast” object.

Privacy & Terms