What's the difference between these two?

What’s the difference between these two?Are these both same?Is spawning and creating new instances with NewObject<class>() same?
The process of creating a new instance of an Actor is known as spawning.
NewObject<class>() Creates a new instance with an automatically generated name.

SpawnActor<class>() is used for Actor derived classes, such as Pawns, Controllers, anything that is actually present in the world. It does some additional stuff to setup Owner Chains and stuff like that which becomes important for Actors.

NewObject<class>() is used for Object derived classes (which does include Actor, but shouldn’t be used for Actor). These are things that don’t ACTUALLY exist in the world, they’re just information, and are handled very differently than Actors are in terms of destroying, memory/performance handling, and their capabilities. They have no Location, or relevance to anything but classes that use them because they’re really data-holders.

best way to explain it think!

These methods create objects other than Class default object?

I have a one more question.We have a Class Default Object so why do we need to create more objects ? such as in case of ALightSwitchCodeOnly(CDO) we have only one object.In what scenario we may need to create more objects?

It depends on what you mean by “Class Default Object”. All of those functions can be ran more or less at anytime during gameplay. They don’t have to be creating default objects. For example, you could be playing an RPG game where you have “quests” to complete, but instead of having all the quests created as default objects you could create them as you unlock them. So you talk to a Barkeeper and he gives you a new quest, you can then use NewObject<class>() to create your own custom class UQuest which holds information about the quest.

All of those functions are just variations of NewObject(), depending on the situation you might want more complex or less complex of a creation method, you can pick one based off of that.

As for whether or not you need to create more objects it’s really up to what you need, some people need a handful, others only one. It depends on what you’re trying to achieve.