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.
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.
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.
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…
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.