envenger
(envenger)
August 12, 2014, 11:00am
1
I have a structure
USTRUCT()
struct FIgnoreActor
{
GENERATED_USTRUCT_BODY()
AActor* IgnoredActor;
int16 TimeIgnored;
FIgnoreActor()
{
IgnoredActor = NULL;
TimeIgnored = 0;
}
};
When I create a new structure of the array, I want to initialize it in the following way.
FIgnoreActor TempStruct = FignoreActor(Actorxyp, 10);
But I am unable to do it. I can do it in this method now though
FIgnoreActor TempStruct;
TempStruct.IgnoredActor = OtherActor;
TempStruct.TimeIgnored = TimeRemoval;
But i want to do it using FignoreActor(
eXi
(Cedric Neukirchen)
August 12, 2014, 11:11am
2
How about:
FIgnoreActor TempStruct = {Actorxyp, 10};
Isn’t that the normal way to initialize a struct in c++?
Duncan_Dam
(Duncan_Dam)
August 12, 2014, 11:15am
3
Here you go add this in your struct.
FIgnoreActor(AActor* OtherActor, int16 TimeRemoval)
{
IgnoredActor = OtherActor;
TimeIgnored = TimeRemoval;
}
envenger
(envenger)
August 12, 2014, 11:35am
4
Yup but I think that method doesn’t work in UE.
Crzyhomer
(Crzyhomer)
August 12, 2014, 9:24pm
5
This would be the proper way to do “constructors”, vs “initializer lists” below. Please add a UPROPERTY() above your actor pointer usage otherwise the object will be garbage collected shortly after it is instantiated.
Also, your example uses a version of your code created in stack memory rather than heap memory. It won’t last long, so you either need this to be a member variable of some other class (also with UPROPERTY) or it needs to be allocated with the new operator.
envenger
(envenger)
August 12, 2014, 10:19pm
6
Ok I will add an UPROPERTY() on top.
The structure is initialized above a class declaration. Something I read in this tutorial.
I don’t know if its the correct way to do it or now.
After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...
Reading time: 1 mins 🕑
Likes: 14 ❤