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"

Cannot Emplace Elements to TArray

I'm currently trying to save the image and mesh of my pickup objects. I have created my own save game object with a PickupIcon and PickupMesh Tarray, of types UTexture2D and UStaticMeshComponent respectively.

SaveGame->PickupIcon.Emplace(*PickupIcon); SaveGame->PickupMesh.Emplace(*PickupMesh);

When I try and compile this i get the following error. Error C2248 'UTexture2D::UTexture2D': cannot access private member declared in class 'UTexture2D' and the same but with UStaticMeshComponent for the other error. I am quite new to C++ and UE4 so am probably missing something obvious but couldn't find anything anywhere online so any help would be appreciated.

p.s. Do let me know if you need any more info as this is my first time posting on here!

Product Version: UE 4.17
more ▼

asked Jan 30 '18 at 11:38 PM in C++ Programming

avatar image

1 1 2

avatar image staticvoidlol Jan 31 '18 at 02:02 AM

The errors are telling you that you are trying to access members (functions or variables) of an object (UTexture2D) that are declared private, i.e. not allowed to be accessed from outside the class itself. Could you post some more code so we can see exactly what you're doing?

avatar image kingofmaglos Jan 31 '18 at 07:51 PM

So the code i wrote above, SaveGame->PickupIcon.Emplace(*PickupIcon); is from a function in my own class called Pickup.cpp They access an element called SaveGame which is passsed as a pointer to the function. The SaveGame has two Tarray objects as already talked about above. These are both public memebers of the UMySaveGame.h class. The PickupIcon is a pointer to a UTexture2D and is in the class PIckup.h and is a private member but it doesn't fix the problem if i make it public. It would seem that when the Emplace function is called it is trying to access elements of the PickupIcon Utexture2d but it can't because these are private. Although then how would it copy an UE4 inbuilt type in general and I have the same line above but for a bool variable and it works fine for that. Thanks for your help and do ask if i need to clarify anything else.

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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