Page 1 of 1

Tips: How do I...

Posted: Tue Aug 25, 2015 6:40 am
by []KAOS[]Casey
This is a topic about random things that you can do in C++ that are not obvious.



How do I... Iterate over all objects that are relevant to me?

Code: Select all

for( TObjectIterator O; O; ++O )
{
}//Iterate over all UObjects. 
How do I... Convert a "FString" into const TCHAR*? (useful for logging)

Code: Select all

FString F= FString::Printf(TEXT("%s"),TEXT("nedm"));
GLog->LogF(TEXT("%s"),*F);

//the "*" operator on FString converts your FString into a const TCHAR. 

How do I... Convert a  const TCHAR* to FString?

Code: Select all

const TCHAR *Str = TEXT("nedm");
FString F= FString::Printf(TEXT("%s"),Str);
How do I... Load an arbitrary class?

Code: Select all

(UTexture *)StaticLoadObject(UTexture::StaticClass(), NULL,TEXT("Engine.S_Actor"), NULL,LOAD_NoWarn | LOAD_Quiet,NULL);//Load Engine.S_Actor texture.

...More to come.

Re: Tips: How do I...

Posted: Tue Aug 25, 2015 9:10 am
by Masterkent
How do I... Convert a  const TCHAR* to FString?

Code: Select all

const TCHAR *Str = TEXT("nedm");
FString F= FString::Printf(TEXT("%s"),Str);
Why not just use FString constructor here?

Code: Select all

FString F = Str;
FString F2(Str);
auto &&F3 = FString(Str);
Pre-227 version does not have such a ctor?

Re: Tips: How do I...

Posted: Tue Aug 25, 2015 4:19 pm
by []KAOS[]Casey
That works too, but printf is generally more useful (albeit slower)

Re: Tips: How do I...

Posted: Thu Oct 22, 2015 7:52 pm
by han
You can also use the LoadObject() template instead of using StaticLoadObject() directly. This equivalent for for the above example would be:

Code: Select all

LoadObject( NULL, TEXT("Engine.S_Actor"), NULL, LOAD_NoWarn | LOAD_Quiet, NULL );

Re: Tips: How do I...

Posted: Wed Nov 07, 2018 1:57 pm
by atrey
Assuming this is a good post to post a couple of "How do I" questions.

1) Is there some "tick()" equivilent function that loops constantly in-game when coding natively?


2) Similar to question 1, but is there a native looping function that is called in-editor to update that environment? Or is that something that happens in the Render.Render class?


Thanks.

Re: Tips: How do I...

Posted: Wed Nov 07, 2018 4:24 pm
by han
UEngine::Tick() in it's subclasses used in game/editor.

Re: Tips: How do I...

Posted: Wed Nov 07, 2018 6:12 pm
by atrey
UEngine::Tick() in it's subclasses used in game/editor.
Is there a pointer somewhere in AActor, or if not, how would I go about makng one?

Also, is UEngine::Tick() called quicker than UScript's tick?