Summer Work (Day 4)
More Slow Progress
Today I was able to fix one thing and break another. I got the array of my custom class working, but I couldn't populate it. I was able to get 'TArray<ACelestialBody*> bodies;' working by creating a forward declaration with 'class ACelestialBody' at the top of the header file. I vaguely remembered forward declaration from an online C++ class I took two years ago which led me to this solution.
When I finally got that done, I went on to try to fill that array with all of the celestial bodies in the scene. In blueprint this could be done with a 'GetAllActorsOfClass' node, but in C++ it isn't so easy. I looked around for a good while trying to find alternatives. I found something called 'TActorIterator' which seemed to iterate through all actors of a class on the scene which was just what I wanted. The only problem was it would not work if I passed it any class that wasn't 'AActor'. This frustrated me for so long that I eventually gave up and decided to work ahead on the logic for updating the positions and velocities of the planets.
All I had to do was on tick call two functions on each celestial body in the scene. I did a simple for each loop and that worked fine. The problem came when I tried to call the functions. I don't know if I am missing something, but every time I tried to use the body variable from the bodies array it would say something like "pointer to incomplete class type is not allowed". I think the case here is just that I don't know what I don't know. Maybe learning C++ outside unreal first would have been better.
When I finally got that done, I went on to try to fill that array with all of the celestial bodies in the scene. In blueprint this could be done with a 'GetAllActorsOfClass' node, but in C++ it isn't so easy. I looked around for a good while trying to find alternatives. I found something called 'TActorIterator' which seemed to iterate through all actors of a class on the scene which was just what I wanted. The only problem was it would not work if I passed it any class that wasn't 'AActor'. This frustrated me for so long that I eventually gave up and decided to work ahead on the logic for updating the positions and velocities of the planets.
All I had to do was on tick call two functions on each celestial body in the scene. I did a simple for each loop and that worked fine. The problem came when I tried to call the functions. I don't know if I am missing something, but every time I tried to use the body variable from the bodies array it would say something like "pointer to incomplete class type is not allowed". I think the case here is just that I don't know what I don't know. Maybe learning C++ outside unreal first would have been better.
Comments
Post a Comment