I’m not sure exactly how your project is coded, but this seems like something you could do with a cast somewhere.
You could also double check to put your includes at the top for everything.
EDIT: Also, when you say “main.cpp,” do you mean the main file that is standard in C++ or is that just what you named your character file? Because I’m pretty sure most people don’t interact directly with the actual main file when using Unreal. Did you make your files directly in your C++, or did you go through the unreal editor and make a C++ class?
2nd EDIT: Hold on. You added pictures. I’m going to go take a look.
Okay. I don’t pretend to be amazing with C++, but I think I can help this one…
So, first of all for your main question: you could use an overlap event to cast. You want to check if the OtherActor is the weapon you want and then get the scene component off the other actor. This video shows how to use overlap events UE4 c++ OnComponentOverlap and OnComponentHit syntax - YouTube .
In your character’s .h file, you could have UPROPERTY() class ARangedWeapon* TestCast;
Then, inside the overlap event in the cpp, you could type TestCast = Cast(For some reason the message board won’t let me use the triangles here, but you need “ARangedWeapon” in between the “<>”)(OtherActor); …Trying again…Cast “ARangedWeapon” (OtherActor); But replace the “’” with the "<"s. I don’t know why the message board won’t let me type the triangles directly.
Then an if statement: if (OtherActor && TestCast == OtherActor)
{
OtherActor->MuzzleLocation …and whatever it is you wanted to do with MuzzleLocation now that you have it
}
I have created a code where my main.cpp file has a void Attack function.
The functionality is
The main.cpp has the attack montage
The weapon.cpp has the equip void and a collision sphere
When the character overlaps the collision sphere the weapon attaches the weapon socket.
Question.
I have to get the USceneComponent* MuzzleLocation from my weapon.cpp in my main.cpp, but I am not sure how i get it into my main.cpp? I need it to get the FVector SpawnLocation at the muzzle, so I can set the projectile.
Okay, it keeps cutting off what I’m trying to say because I’m using the triangles. Just replace the “” with the things above “,” and “.”. Apparently, the message board interprets anything with the triangles as not posted for some reason.
So, replace those things. And then later in the same overlap event:
if (TestCast && TestCast == OtherActor)
{
TestCast->MuzzleLocation …then do what you wanted to do after you get the MuzzleLocation here!
}
Also, I’m still not clear if this is directly from your character file overlapping or if you are trying to manage two other objects overlapping each other from a third “main” file.
And, I see you have some errors at the bottom of your picture. Did those only pop up when you were trying to do your current action, or are they from something else?
Okay, so I followed the advice to use AActor* OtherActor, then cast ARangedWeapon* Weapon to the OtherActor input. That did the trick. Thank you very much!