Hello, I have made a AStar and ASolarSystem c++ actor classes. In my ASolarSystem class I’ve made a TArray<AStar> Stars*.
My code generates a random amount of stars and adds them to this Stars array.
The AStar class has a sphere mesh, to represent the star in 3D space. When I make a blueprint of just the AStar class, the sphere appears in the viewport without issues.
My issue now is that even after creating a DefaultSubobject for every star I generate inside my ASolarSystem class, I don’t see any of them in the 3D space, only inside the Details panel.
Because the star is an actor. An actor, by definition, can’t be a component. You can attach them though, but they won’t appear in the blueprints viewport.
Also, if these stars are going to just be static spheres, it would be better to use an instanced static mesh. Depending on what you’re planning with them, you might not even want them attached. You certainly wouldn’t want them as components- selecting a single star would be extremely annoying.
Oh I see, thank you. So I have to spawn them individually (with something like GetWorld->SpawnActor()).
How might I be able to spawn them in world space and at the same time keep a reference to them inside my ASolarSystem class? (to have them “belong” to another actor).
I thought of setting up a one-to-many relationship and give each star a SolarSystem variable that indicates what system they are a part of, in addition to the Stars TArray that is in my SolarSystem, but that introduced issues such as circular “include” statements.
I think it highly depends on what you want to make and how you want to do it.
I assume your ASolarSystem class spawns all the stars since you may want to change how stars spawn with different SolarSystem subclasses.
You may want to use a combination of FString and AActor* variables on the star rather than direct reference to the solar system (ASolarSystem* SolarSystem).
But again, this depends on the role of your SolarSystem.
If the solar system just spawns the stars then acts as nothing but a coordinate, keeping a name and referencing as an actor would be more than enough.
If your solar system has more variables than name and position, you may want to create a USolarSystemInformation : public UObject that holds all the information.
Such as: AActor* ActorReference; FString Name; FVector Location; TArray<AActor*> Stars; etc.
Every single star in a solar system would have a reference to the same UObject, including the solar system itself.
This allows the stars to be able to reference all needed information without creating circular includes.
Though these suggestions may not fit- it really depends on what role the solar system is playing.