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"

How to remove nullptr as a key from TMap

Hello guys:

I am writing a Threat Map for target selection for battle that has a large number of AI. Sometimes, here is my Tmap declaration:

TMap ThreatMap;

Like so, I am using the Character ref to find the threat value in the TMap. Sometime, the key = nullptr, and I try to remove it with ThreatMap.Remove(Key), however the Tmap nullptr key element is still there. Anyone know what is going on?

Thanks

Product Version: UE 4.17
Tags:
more ▼

asked Mar 03 '18 at 01:39 AM in C++ Programming

avatar image

ShankIsUsed
18 2 4 6

avatar image GIGA-Money Mar 03 '18 at 04:17 AM

...........................so C++ its great isn't it. NULL POINTER (nullprt) is ........well here is some info https://stackoverflow.com/questions/14189709/why-cant-you-take-the-address-of-nullptr if you didn't have that NULL POINTER you would crash your system (weather soft or hard crash) so no you can't remove that. You will need more info on pointers to continue.

avatar image GIGA-Money Mar 03 '18 at 04:20 AM

http://www.cplusplus.com/doc/tutorial/pointers/ more pointers.

So you need to assert the condition, if its null then move on, write to that spot, not sure what your doing.

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

1 answer: sort voted first

First of all, it's a little odd that you're using a pointer as a key in an associative array. It's not wrong necessarily, just strange. I think personally I'd use the name of the character instead of the pointer to it.

Second, how are you using this? You're not putting nullptr into the TMap yourself, are you? (Don't.) It's that you have a character that has been removed from the scene, so its reference is null right? If that's the case, then it's likely because the garbage collector doesn't care about the TMap keys. (But that's just a guess, I haven't looked at the TMap code). To test that theory, Try making an additional TArray and put each character in that array as well. The garbage collecter does respect the TArray, so it will prevent the characters from being removed while they're still in use in the TMap.

Obviously that shouldn't be your final solution, but it might help you figure out what is happening.

more ▼

answered Mar 03 '18 at 06:51 AM

avatar image

Inconceivable
27 3 3 12

(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