Announcement

Collapse
No announcement yet.

How can I get parameter of the Character in a different file .cpp?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How can I get parameter of the Character in a different file .cpp?

    I need get Relative Location of my character in different cpp file (not Character.h or Character.cpp). How i can do this?
    For example:
    Code:
    AFPGCharacter::capsule_component->SetRelativeLocation(0.f, 0.f, 0.f);
    Last edited by INF20; 11-21-2020, 04:24 PM.

    #2
    What file are you wanting to get that in?

    Comment


      #3
      That's not how code works, in C++.

      Code just defines the structure of an object, the object has to be instantiated to be used. Once the object is instantiated (e.g., created, spawned, static allocated, whatever) - you have to get that Object from the system to access properties on that Object. You can use things like a TActorIterator or something like that to find your object.

      Code:
      // Assuming this code is called in some UObject which has access to the GetWorld() method.
      for(TActorIteractor<AFPGCharacter> It(GetWorld()); It; ++It) // Find every AFPGCharacter in the current World.
      {
        if (AFPGCharacter* MyCharacter = *It)
        {
           MyCharacter->CapsuleComponent->SetRelativeLocation(0.0f, 0.0f, 0.0f); // Access this Character Object, Access the Capsule Component member, and set the RelativeLocation on that component.
        }
      }
      That's not the only (or best) way to find the object. It's just an example. There's a thousand ways you could find that object - it just depends on the situation.

      If you're new to C++, or coding in general, I'd take a look at some of the various tutorials online. Supposedly the UDemy course is pretty good: https://www.udemy.com/course/unrealcourse/
      Able Ability System - A high performance, robust ability system for UE4. Now Available!

      Comment


        #4
        Originally posted by ExtraLifeMatt View Post
        That's not how code works, in C++.

        Code just defines the structure of an object, the object has to be instantiated to be used. Once the object is instantiated (e.g., created, spawned, static allocated, whatever) - you have to get that Object from the system to access properties on that Object. You can use things like a TActorIterator or something like that to find your object.

        Code:
        // Assuming this code is called in some UObject which has access to the GetWorld() method.
        for(TActorIteractor<AFPGCharacter> It(GetWorld()); It; ++It) // Find every AFPGCharacter in the current World.
        {
        if (AFPGCharacter* MyCharacter = *It)
        {
        MyCharacter->CapsuleComponent->SetRelativeLocation(0.0f, 0.0f, 0.0f); // Access this Character Object, Access the Capsule Component member, and set the RelativeLocation on that component.
        }
        }
        That's not the only (or best) way to find the object. It's just an example. There's a thousand ways you could find that object - it just depends on the situation.

        If you're new to C++, or coding in general, I'd take a look at some of the various tutorials online. Supposedly the UDemy course is pretty good: https://www.udemy.com/course/unrealcourse/
        It's not working.
        Attached Files

        Comment


          #5
          They are depreciating pawns Iteractor. Try getting the controller then the pawn from it. Have not tested but should work.
          Code:
          for (TActorIteractor<AFPGController> It(GetWorld()->GetControllerIterator()); It; ++It) // Find every AFPGController in the current World.
          {
               if(It.GetPawn())// Find a AFPGCharacter in the current World.
                   It.GetPawn()->CapsuleComponent->SetRelativeLocation(0.0f, 0.0f, 0.0f); // Access this Character Object, Access the Capsule Component member, and set the RelativeLocation on that           component.
              
          }
          Last edited by gamepainters; 11-22-2020, 01:37 PM.

          Comment


            #6
            Originally posted by INF20 View Post

            It's not working.
            Its that portal actually in the world? Did you try stepping through? Copy and pasting my code without understanding it isn't going to get you anywhere.
            Able Ability System - A high performance, robust ability system for UE4. Now Available!

            Comment


              #7
              It would be a lot easier and faster if you were more specific or perhaps a better explanation of what you're trying to achieve.

              What exactly are you trying to do? You say "get parameter of the Character", but is it only the player or all characters in the world? You have a portal with a box component, so you want to access the character that overlaps that box or what?
              "I have harnessed the shadows that stride from world to world to sow death and madness."

              Comment


                #8
                Originally posted by EvilCleric View Post
                It would be a lot easier and faster if you were more specific or perhaps a better explanation of what you're trying to achieve.

                What exactly are you trying to do? You say "get parameter of the Character", but is it only the player or all characters in the world? You have a portal with a box component, so you want to access the character that overlaps that box or what?
                yeah that would help a ton, plus i see you are putting that into a tick function? why would you want to resize the capsule on every tick on every character?
                Are you wanting to just set it once, then that is it? are you after one character, the one that is in your portal? or all them? answer these questions then we could help you much easier.

                Comment

                Working...
                X