What is Unreal equivalent of Unity gameObject.parent? - unreal-engine4

In the Unreal Blueprint Editor I have a hierarchy of components with a Scene parent and Pose Mesh child. I can get the component in Unreal through GetParentComponents(), but this returns an array while I just need the Scene component and not every parent. GetOwner() also doesn't return the direct parent.
If I have PoseableMesh component, how do I get the offset scene component?

I used a Get Attach Parent node, with PoseableMesh as Target.
From the documentation:

Related

How can i reset positions of Prefab children's in unity 2d. children's are also prefabs

I have an object which is prefabs and that object contains further objects(assets) which are also prefabs. I want to Reset position of Parent object and Children object when level fails. however I am not able to reset position of children object by instantiating. I can instantiate parent object but can not instantiate children objects. when I reload the scene, Scene get reloaded with the object which was active when game started not with the object on which level failed.
for reset all children's transform you can get it by GetComponentsInChildren<> like this:
Transform[] childList=parentObj.GetComponentsInChildren<Transform>();
foreach(var i in childList)
{
i.localPosition = Vector3.zero;
}
you can call it after instantiating prefab or after restarting game.
another way is attach an script to each children of prefab and in awake or start function reset the position. if it should not rest by zero you can store your default transform and set it on awake or start function.

Object is not clickable when it is a child of another object in unity

So, i made a simple code in unity that outputs "clicked" when the object is clicked by using this simple code :
private void OnMouseDown()
{
Debug.Log("clicked");
}
it displays the message when clicked, but when the same object is a child of another object it is not clickable and doesn't display the message.
How do i make it clickable when it is a child ?
You should always be aware of the colliders of parented objects. When the collider of your child object is within the collider of the parent object the OnMouseDown trigger will only hit the first collider it (well) collides with.
You need the collider of the child object to be reachable.
You can deativate the collider of the parent object.
You can scale the collider of the child object up.
Or you write your own method, which only checks colliders with a given tag.
Just add a Rigidbody to the parent object (probably in your case you also need to set "Is Kinematic" to true) and make sure child objects have colliders.

how to parent follow children in unity

I make an empty game object and added sprite render component. Then because of inconsistency sprite renderer and NavmeshAgent I was forced to create one Emptygameobject as child of parent EmptyGameobject then add NavmeshAgent
component.in runtime. I need parent Gameobject follow childgameobject.
I write a class for navmesh move and I attribute it to objects by drag and drop it. look like this :
All the objects in this class are moving.
Following the child object is not done correctly.
that move class called in the following form
why would you want to move the child with the parent following, you can just move the parent. the child will follow and there will be no difference in functionality

How to keep references to UI elements in a prefab, instantiated at runtime

I have a prefab, which has a script component as MonoBehaviour. This script has 3 public fields as text; which are assigned in the inspector, before saving the gameobject and remove it from the scene.
Now, this works fine if I have a UI element, like a panel. Every text field on the panel, defined in the prefab, is still assigned when the prefab is instantiated at runtime.
This sadly does not work on another prefab that I have made; which is not a UI element. In my case it is a meshgameobject with various components on it (navmesh agent, capsule collider, rigidbody, animator and so on)
I believe this is due the fact that with the UI panel, the elements are already in the gameobject hierarchy, while when the reference is on a different gameobject; Unity does not keep track of them.
This means that I have to always add at runtime via code, the elements that I want to reference on each prefab, if they are not part of the game object itself? In this case I would just avoid to have my references public then, since I won't be using the inspector in this case (every gameobject of this type is instantiated at runtime).
Just checking if there is any other solution to work around this.
Use List to save reference for each generated object.
Lets assume that the object you want to add to store the reference is called meshgameobject.
Example:
List<meshgameobject> meshGOB;
initiaize inside Start function
void Start(){
meshGOB = new List <meshgameobject>();
}
Then create and use list.add() to add reference during runtime like
meshGOB.Add((meshgameobject)Instantiate(prefab, Pos, Quaternion.Identity);
OR
meshgameobject tempGOB= (meshgameobject)Instantiate(prefab, Pos, Quaternion.Identity);
//Do something with meshgameobject
tempGOB.someAction......
then add the reference to the List
meshGOB.Add(tempGOB);
Do not make a perfab which references to other gameobjects in the scene but are not in the hierarchy of the perfabI itself. AFAIK, Unity can not track this kind of references.
Even if Unity supported this kind of prefab, you could not use this kind of prefab in other scenes because the specific references, so it is not make much sense to make a perfab like that. If you have to make it a pefab just because the scene and the game object are maintained by different person, you may use Find() to populate the references at runtime.

How to change prefab in Unity3D editor mode by coding

i am writing a MenuItem to apply some modification to a series of prefabs. what i was thinking to do is below:
Instantiate the prefabs one by one
apply the modification to the instance
save the instance to prefab using PrefabUtility.ReplacePrefab
a piece of code would like this:
GameObject sequenceObject = Instantiate(Resources.Load("Cinematic/"+sequenceName)) as GameObject;
Object targetPrefab = PrefabUtility.GetPrefabParent(sequenceObject);
// do some change to the sequenceObject
PrefabUtility.ReplacePrefab(sequenceObject, targetPrefab, ReplacePrefabOptions.ConnectToPrefab);
the problem is that targetPrefab is null
and the instance of the prefab generate by the code in the Hierarchy is called xxxxx(Clone), which is different with the one when i drag a prefab into Hierarchy, and the latter one can using the method above to modify the prefab.
so anyone can help?
Edit1: my question is the same as this one: Instantiate Prefab but not linked to the prefab, but the solution is not i want
Finally, I found the solution:
GameObject sequenceObject = PrefabUtility.InstantiatePrefab(Resources.Load("Cinematic/" + sequenceName)) as GameObject;
This is what I want.