Components documentation and instanced definition.

Hey,

While reading the second paragraph of the components documentation, i got quite confused. I feel it is slightly misleading, that or i just don’t understand whats going on.

“Contrary to the default behavior of sub-objects in general, Components created as sub-objects within an Actor are instanced, meaning each Actor instance of a particular class gets its own unique instances of the Components.”

Here if you don’t know about the instanced keyword you might think that that sub-objects, while the game is running, all point to the same object, i don’t know this might be strange but this confused the hell out of me when reading this.
From my understanding like any c++ class, properties are all new and separate instances when you instance the class. (Edit: if not a pointer of course, sub-objects are used as pointers so it could well be that we have only one instance per class)
The way I understand this now is that, when looking at the class in editor or placing in world, each of these separate base instances get a separate instance that you can edit, instead of all these instances starting with the same defaults.
Now I am using instanced a lot here and it seems that I use it for things that should be described with another word.

I feel the second part just makes the misunderstanding worse for me:

“A simple way to visualize this is to imagine the vehicle described above. A Car class might use Components to represent the wheels of the car. Four Wheel Components would be created as sub-objects in the default properties of the class and assigned to a Wheels] array. When a new Car instance is created, new instances of the wheel Components are created specifically for that Car. If this were not the case, when one Car in the world moved, the wheels of all Cars would turn; which is clearly not the desired behavior. Instancing of Components by default simplifies the process of quickly adding unique sub-objects to Actors.”

This gives me the impression that if I create a UObject with with a variable B and assign 4 of them as sub-objects of an actor. When modifying variable B on one actor all other instances of this actor will have this the change to B reflected to them because there is only one version of B all pointed to by the separate actor instances

Anyway I wonder if anyone else had this same confusion? Is it just me? I’m feeling quite stupid at the moment, wondering if i’m just missing some huge part of the puzzle.

What I think is going on is a misunderstanding on the vocabulary and this might be emphasized by the fact that we don’t have much documentation on CDO’s, what it really means to place an actor in a world window etc. That and the word instanced which is used, I think, here with a different context to which most programmers are used to.

No answers? Let me know if my post would need to be edited and what I mean described better.

The confusion may be coming from different software packages using the term “instance” differently. This use of the term is more like the standard English definition, “an example or single occurrence of something.” In other words, if you have three AActors in your level, that would be three instances of the AActor class. What is being said about tires on cars is that each car actor has four instances of the wheel component. This would mean that three cars have a combined total of twelve wheels. Modifying any one instance, say, by getting a flat tire, would only affect that one specific tire (i.e. that one instance).

You also mentioned some confusion about the CDO, or Class Default Object, so let’s go over that briefly. UE4 creates one “master copy” of each registered class (UCLASS). When you want to create a blueprint from that class, the blueprint’s default property values are copied from the CDO. That’s also how UE4 knows when you’ve changed something and provides the yellow “reset to default” button. Similarly, when you instantiate a class, such as by spawning an actor, UE4 does it by making a copy of the CDO and then updating some of the properties of the new object. What was said about components attached to the CDO was meant to indicate that components are stored by pointer. This is one of the reasons why the properties are updated after the copy is made instead of just making the copy byte-for-byte and leaving it at that. If UE4 just copied the CDO byte-for-byte, then every car in existence would be pointing to the same four wheels. So if Car #1 tried to spin its front driver-side wheel, it would work, but that wheel also happens to be the same one that Car #2 thinks is its front driver-side wheel. So when a new actor is spawned, its components are copied, and the component pointers on the new actor are fixed to point to the new instances of that component. I hope that helps to clear up what was meant. The really key point is that an instance of a class is a completely separate object unto itself from all other instances. The thing these instances have in common is that they were made from the same mold. They’re clones of each other in that sense, but what happens to one clone doesn’t happen to another.