Hi,
So after googling around for a bit i havent found anyone asking how to do it in c++ .(i only seen alot of blueprint tuts out there)
I have a Spawner Actor , I attached a custom Actor(ObjectPool) component to it.
How do i actually actually access my spawner’s variables ? I came from a c# background and i don’t think
using Spawner.timeToSpawn will actually get me anything in c++.
Some help would be very appreciated.
MrGoatsy
(MrGoatsy)
November 19, 2016, 1:21pm
2
Are you looking for something like this?
Dude, love you thanks so much!
try this->GetOwner(),
it will return your parent AActor, then you cast this pointer to your Spawner actor.
So, you will end up having something like this (using c-cast):
MySpawnerActor* parentSpawner = (MySpawnerActor*)this->GetOwner();
parentSpawner ->yourVariable…
Hey man i need to ask this…
Lets say if i put that in my BeginPlay()
MySpawnerActor* parentSpawner = (MySpawnerActor*)this->GetOwner();
How would i use it in my other functions ?
void SomeFunction::DoSomething(){
parentSpawner->DosomeMethodB();
}
Cause it seems to not be public among the entire .cpp cause it keeps telling me it is undefined in my other function…
So i actually tried to put it in my .header file
MySpawnerActor* parentSpawner;
I seem to be not understanding something here. Need help on this.
Anyways thanks for being so helpful this far !
make this variable as a class member in the .h class definition
class …{
private (or public) MySpawnerActor* parentSpawner;
}
in cpp you will have
parentSpawner = (MySpawnerActor*)this->GetOwner();
when u meant make this variable as a class member…
Do you mean this ?
UPROPERTY()
class MySpawnerActor* parentSpawner;
cause the example you gave is exactly like the one i asked which wasn’t working.
I suggest you read a basic C++ object oriented tutorial.
A class member is:
class.... {
public: (or private:)
MySpawnerActor* parentSpawner; //<-- that's a class member.
}
And inside your c++ you get the instance, wherever you want. in the BeginPlay function, for example:
parentSpawner = (MySpawnerActor*)this->GetOwner();