Trying to get reference to variable

First of all, I’m sorry for my english.
Basically what I trying to achieve, is a reference to variable which is in AActor class from inside ACharacter. Every my attempt is end up crashing ue4editor.

Actually I have TArray inside my AActor and from ACharacter class I want to add him(My Character) to this array.

I won’t gonna post any code, because of that many tries is soo messy, and only thing that I want from you is to post example, please.

do you want to add an Array of references to actors inside a Character-class?
something like:

class AYourCharacter : ACharacter
{
     UPROPERTY()
     TArray<AActor*> someActorArray;
}

then you should look at this: link text

This is a bit confusing because the class ACharacter is a child of AActor. So what it sounds like you have is two separate objects. You have an AActor object and a different object of class ACharacter in your scene. What you are trying to do is add the ACharacter actor to a TArray contained inside of another actor object of class AActor?

“… are trying to do is add the ACharacter actor to a TArray contained inside of another actor object of class AActor?” Yes. But even if i tried to get reference to variable(like float or what) inside AActor from ACharacter, I make editor crashes because i dont even know how to do that. What else can I say is that, I dont have programming in c++ since while so it could be my mistake, this project Im working on is kind of try to get used to c++ again. But really i dont have any problem since yet, this is the first one.

Nope…
Is like:

class ASomething : AActor
{
    UPROPERTY()
    TArray someActorArray;
}

and inside of AYourCharacter

include "Something.h"

....

// DO Some Weird Casting \\

...->someActorArray.Add(Controller->GetPawn());

...

Edit: I did’t know who to make it look right.

I think this is what you want.

You have your AActor object that we’ll call “MyActor” and you have your ACharacter object that we’ll call “MyCharacter”.

I will assume you are getting the MyCharacter object somehow… I have no idea how you are doing it but here is what you do:

Your MyActor will do this stuff:

// create a pointer variable to your MyCharacter object
ACharacter* MyCharacterReference = Cast<ACharacter>(MyCharacter);

// make sure that the pointer variable has referenced the object correctly
// also, it ensures the MyCharacter object is of type ACharacter
if(MyCharacterReference){
    // get the float variable "TheFloat" from the MyCharacter object
    float SomeFloat = MyCharacterReference->TheFloat;
    // do things

}

Honestly, I’m still not sure exactly what you are trying to do here.

Adjusted Code

I think this is what he is trying to do.

The same thing but from inside of what you call MyCharacter to MyActor.
I mean in MyCharacter I want to get some variable from MyActor.

edit: I corrected what I wrote

In your MyCharacter.h file, you include the MyActor.h

MyCharacter.h
#include “MyActor.h”

Then, in the MyCharacter.cpp file, you do what I did above but for the MyActor

/

/ create a pointer variable to your MyActorobject
MyActor* MyActorReference = Cast<MyActor>(MyActorObject);
 
// make sure that the pointer variable has referenced the object correctly
// also, it ensures the MyActor object is of type MyActor
if(MyActorReference){
    // get the float variable "TheFloat" from the MyActorobject
    float SomeFloat = MyActorReference->TheFloat;
    // do things
 
}

there are so many things you could be doing wrong… Like the whole pointer vs. smart-pointer thing… private public encapsulation… the unreal header tool and the macro defines like uproperty… object instantiation…

have you worked through the c++ tutorial?
link text
link text

I could offer german as an alternative to english…

Dave4723 is right. This is some fundamental C++ stuff. You should go through some tutorials for sure.

AnXgotta that the answer. I just forgot that I should put it in “In your MyCharacter.h file, you include the MyActor.h”.

I spend 2 nights on it. Sorry for problem… Thanks you very much AnXgotta, and you Dave4723.

Well good. I’m glad we were able to help. =) Don’t forget to Accept the answer so it gets marked “RESOLVED” on the forum.

and use your compiler output…
then you can find out if it’s an include error or if there are problems with smart pointers etc…
you should have gotten an error like “unknown type “AMyActor” …”

You mean output log? Because VisualStudio doesn’t give me any error, and let me compile(as I said just editor crash afrer runing project). Anyway, now every thing is working correctly even my Tarray. Thanks again.