Finding Objects, Casting, and pointers
I've read that TObjectIterator is used to find any class, How do you use it. Can someone show me some example code of how to use it to find a custom class?
Also how does casting work. Say I'm looking to cast to my custom character class Called AMainCharacter.
AMainCharacter* mainChar= Cast(GWorld->GetFirstPlayerController()); would just get a ACharacter right? Not a AMainCharacter? Can someone show me example code and explain please.
How could I find or set a pointer to a custom class. Like for instance I made a UMG Class called UItemWidget derived from UUserWidget what would be the best way to get reference to that UItemWidget. Would it be storing a pointer, if so what is the best way (with code example)? Or are there Unreal functions that can find that class? In bp Get Actors of Class doesn't even allow me to select UItemWidget in that dropdown, its not even listed. How could I find a custom class like this?
For your first point you probably don't want to search all available actors or iterators for a specific instance of a class, but there are a variety of simpler use cases in engine code that you can reference as an example. Here's an example
For casting you need to include the template value so it would be AMainCharacter* mainChar= Cast(GWorld->GetFirstPlayerController()->GetPawn()); //note i added the GetPawn bit as I asume you dont want to cast a playercontroller to a character.
I'm having trouble understanding your third question. I think you might want to do some standard C++ tutorials and lookup the topic of Encapsulation. What you want is a pointer to a class instance returned from some class that has owner of that pointer. The class instance should have getters/accessors for the members that are publicly available.
answered Oct 28 '14 at 05:24 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here