x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Initializing a simple class variable?

Lets say that I have a variable foo which is of the type SomeClass* in my header file and I want to initialize it in the constructor of my source file.

How should I go about doing that?

Would it require using NewObject or ConstructObject?

Would the method be different if SomeClass inherited from UObject or AActor?

Product Version: Not Selected
Tags:
more ▼

asked Dec 30 '14 at 05:39 PM in C++ Programming

avatar image

BitBoy92
488 53 38 57

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hi Farshooter

yes, it would be different. For UObject, if SomeClass inherits from it, you go;

 foo = NewObject<SomeClass>();

If its an actor you'd spawn it, and I don't think you could do that in a constructor..

more ▼

answered Dec 30 '14 at 05:58 PM

avatar image

robbiecooper
766 79 60 234

avatar image BitBoy92 Dec 30 '14 at 09:15 PM

When would you ever need to use ConstructObject?

avatar image robbiecooper Dec 30 '14 at 09:27 PM
avatar image BitBoy92 Dec 30 '14 at 09:37 PM

Okay. Your answer does help clear up that issue. I have one last question. How do I initialize a class in Unreal that doesn't inherit from UObject.

Would the following code be acceptable or would you do it differently in Unreal? SomeClass* foo = new SomeClass();

avatar image robbiecooper Dec 31 '14 at 08:41 AM

Yes, that's how you initialize structs. Or often you can cast- to custom game mode, say, from a UGameplayStatics function; https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Kismet/UGameplayStatics/index.html Or initialize a pointer to NULL. The rest I do in blueprints. Spawning actors for example, I do in bp's.

avatar image BitBoy92 Dec 31 '14 at 06:41 PM

Thanks for the help! Your last post really helped to clear up my confusion.

avatar image robbiecooper Dec 31 '14 at 03:58 PM

Hey Farshooter- dont let me go into the new year with 404 karma... :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question