Download

Strings?

So I tried to setup several types of strings to accomplish this task.

There is this line of code.
, IdleAnimationAsset(TEXT("/Game/ZZSSP/Sprites/animation/animation/animation.animation"))

I want to instead put a string variable where the quotations are.
, IdleAnimationAsset(somevariable)
I also tried:
, IdleAnimationAsset(TEXT(somevariable))

I’ve tried the std strings, I’ve tried FTExt, FName, anything I could find on the subject. It accepts none of them. What am I doing wrong?

Thank you once again for your kind help.

Have you tried FString?

.h
UPROPERTY(Category = CharacterAnimation, VisibleDefaultsOnly, BlueprintReadOnly)
FString idleanimation_set = “/Game/somepath”;

.cpp
IdleAnimationAsset(TEXT(idleanimation_set))
Throws: Itendifier “Lidleanimation_set” undefined.

and

IdleAnimationAsset(idleanimation_set)
Throws: Nonstatic Member Reference

The following works perfectly fine for me:

Illegal reference to nonstatic member.

Does it matter that I am setting this up in a struct?

	// Setup the assets
	struct FConstructorStatics
	{
		ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> IdleAnimationAsset;

		FConstructorStatics()
			: IdleAnimationAsset(idleanimation_set)
		{
		}
	};

This isn’t all of the code. I just trimmed it up.

This is the UPROP in the .h.

UPROPERTY(Category = CharacterAnimation, VisibleDefaultsOnly, BlueprintReadOnly)
FString idleanimation_set = TEXT("/somepath");

Just curious - not sure if you pasted your code or typed it, but you line:

IdleAnimationAsset(TEXT(idleanimation_set))

is missing the ‘;’ at the end. Is that just becuase of the post, or is it like that in your code?

I’m not sure, but I don’t think inline assignment is allowed.
Also, can’t test anything on my side because I’ve been struggling reinstalling Visual Studio for two days now.

You don’t put a semicolon there, it is part of an Fstruct. Here is the code:

	struct FConstructorStatics
	{
		ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> IdleAnimationAsset;

		FConstructorStatics()
			//Base Movement Animations
			: IdleAnimationAsset(TEXT("/Idleanimationpath"))
		{
		}
	};

Oh VS problems, those are nasty. I had one so annoying and persistent once I had to re-install windows, no joke.
If you are clearing it out, make sure to clear it out of your common files folder as well in Program Files.

Also, this works for other variable types like bools and such, why wouldn’t it allow an FString? If I set it as an FString in the CPP as a variable in the CPP, it still throws the same error. No UPROPS involved. This is definitely a weird one.

Gotcher - ok, I thought that line was a function call - in the cpp file. Didn’t see it was an inline assignment.

If the problem would be that you are using an FString and the target is expecting a TCHAR* (which you can generate with the TEXT macro) then getting the data pointer from the FString variable would be necessary ( IdleAnimationAsset( *****somevariable) , mind the asterisk operator)

But telling from your error of “Illegal reference to nonstatic member.”, This might not be the problem. We would need to know which member you are accessing (which line fails) and then where the nonstatic member you are trying to access is located then.

(trimmed for paths)
Error .cpp(25) : error C2065: ‘Ltrottinganimation_set’ : undeclared identifier

.cpp
: TrottingAnimationAsset(TEXT(trottinganimation_set))

I get this error on whichever line I set the animation.

.h
UPROPERTY(Category = CharacterAnimation, VisibleDefaultsOnly, BlueprintReadOnly)
FString trottinganimation_set = TEXT("/trotanimationpath");

The class is a paper2d character: APaperCharacter and has a .h located next to it and properly included.

Edit: I tried it with pointers and was given the same illegal access error.

Just for fun I also tried:

UPROPERTY(Category = CharacterAnimation, VisibleDefaultsOnly, BlueprintReadOnly)
TCHAR* trottinganimation_set = TEXT("/Game/trotanimation path");

Unrecognized Type, I figured as much. It wasn’t listed in the documentation as an accepted UPROP type.

you are trying to stringify an object. What TEXT actually does is to make a string literal “this is a string literal” into a unicode string literal if necessary L"this is a unicode wchar_t string literal" (http://msdn.microsoft.com/en-us/library/69ze775t.aspx)

that is why you get an error where the variable name trottinganimation_set is preceded by an L. The result is a name that is not existend and thus ‘undeclared’.

If you want to get a raw string (TCHAR*) out of an FString you have to precede the variable name with the asterisk-operator. That particular operator, normally known as the dereferencing-operator, is overriden in the FString class to yield the internal TCHAR-array-pointer (const TCHAR*)



TCHAR* raw = TEXT("String literal"); // a unicode-lieteral on unicode-systems, an ANSI multibyte-literal on mutlibyte-systems

FString ObjStr(TEXT("String literal")); // an FString object created from a raw string

const TCHAR* raw2 = *ObjStr; // getting a raw string back from the FString object


Thank you for that information! I had no idea how difficult working with strings in Unreal was. Well, not difficult, more like how uneducated I am about it. :stuck_out_tongue: I couldn’t figure it out, so I am just going to overwrite the struct and hope for the best. I will chime back in with how that goes.

Thanks to everyone else that has continued to try and help me. It is very appreciated.

For anyone else having problems and trying to accomplish my tasks, I do have a solution that was staring me right in the face. So on my base character I have:

base.cpp
// Setup the assets
struct FConstructorStatics
{
ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> RunningAnimationAsset;
ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> TrottingAnimationAsset;
ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> WalkingAnimationAsset;
ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> IdleAnimationAsset;

		ConstructorHelpers::FObjectFinderOptional&lt;UPaperFlipbook&gt; NeutAttack1;
		ConstructorHelpers::FObjectFinderOptional&lt;UPaperFlipbook&gt; NeutAttack2;
		ConstructorHelpers::FObjectFinderOptional&lt;UPaperFlipbook&gt; NeutAttack3;

		FConstructorStatics()
			//Base Movement Animations
			: TrottingAnimationAsset(TEXT(""))
			, WalkingAnimationAsset(TEXT(""))
			, RunningAnimationAsset(TEXT(""))
			, IdleAnimationAsset(TEXT(""))
			//Base Attack Animations
			, NeutAttack1(TEXT(""))
			, NeutAttack2(TEXT(""))
			, NeutAttack3(TEXT(""))
		{
		}
	};
	static FConstructorStatics ConstructorStatics;

	RunningAnimation = ConstructorStatics.RunningAnimationAsset.Get();
	TrottingAnimation = ConstructorStatics.TrottingAnimationAsset.Get();
	WalkingAnimation = ConstructorStatics.WalkingAnimationAsset.Get();
	IdleAnimation = ConstructorStatics.IdleAnimationAsset.Get();

	NeutAttack1 = ConstructorStatics.NeutAttack1.Get();
	NeutAttack2 = ConstructorStatics.NeutAttack2.Get();
	NeutAttack3 = ConstructorStatics.NeutAttack3.Get();

I then do a basic inherit on my extended class, and override it.

extend.cpp
// Setup the assets
struct FConstructorStatics
{
ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> RunningAnimationAsset;
ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> TrottingAnimationAsset;
ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> WalkingAnimationAsset;
ConstructorHelpers::FObjectFinderOptional<UPaperFlipbook> IdleAnimationAsset;

	ConstructorHelpers::FObjectFinderOptional&lt;UPaperFlipbook&gt; NeutAttack1;
	ConstructorHelpers::FObjectFinderOptional&lt;UPaperFlipbook&gt; NeutAttack2;
	ConstructorHelpers::FObjectFinderOptional&lt;UPaperFlipbook&gt; NeutAttack3;

	FConstructorStatics()
		//Base Movement Animations
		: TrottingAnimationAsset(TEXT("/Game/spriteflipbookpath"))
		, WalkingAnimationAsset(TEXT("/Game/spriteflipbookpath"))
		, RunningAnimationAsset(TEXT("/Game/spriteflipbookpath"))
		, IdleAnimationAsset(TEXT("/Game/spriteflipbookpath"))
		//Base Attack Animations
		, NeutAttack1(TEXT("/Game/spriteflipbookpath"))
		, NeutAttack2(TEXT("/Game/spriteflipbookpath"))
		, NeutAttack3(TEXT("/Game/spriteflipbookpath"))
	{
	}
};
static FConstructorStatics ConstructorStatics;

RunningAnimation = ConstructorStatics.RunningAnimationAsset.Get();
TrottingAnimation = ConstructorStatics.TrottingAnimationAsset.Get();
WalkingAnimation = ConstructorStatics.WalkingAnimationAsset.Get();
IdleAnimation = ConstructorStatics.IdleAnimationAsset.Get();

NeutAttack1 = ConstructorStatics.NeutAttack1.Get();
NeutAttack2 = ConstructorStatics.NeutAttack2.Get();
NeutAttack3 = ConstructorStatics.NeutAttack3.Get();

No need to create extra UPROPS, just use the ones we have.

So my apologies to the future someone looking for the answer here, I just decided to bypass the problem in a more sane way.

Thanks again everyone. Note, that if you leave the base class blank as I did in this example, you will get a compiler warning about missing assets. You may want to default it to something else like a blank sprite to avoid annoyance.