There are many identical objects, each of which has a child.
The child object must not appear outside of the parent. I do this using SpriteMask, but with this approach, the child object sees within the boundaries of someone else's parent, as in the screenshot
Related
I'm trying to use child actors in the following way: I have my main character with a child Actor, I want that to be the chasis for my ship, this will have some functionality so having it as a BP should work fine. The chasis will also follow the same principle and I want to attach different mods to the chasis but first I want to use the bare chasis inside my character.
However, when I select my chasisBP in the child Actor my character stops moving. This is only when the child Actor is setted. What I had before was just a static mesh and with that I can move freely.
I have one doubt, how to get Child object child. I have one parent Gameobject name bed_1 that parent have four child object in that four child object one child have another 5 child how to get that 5 child!
Detailed Image:
transform.GetChild(3).GetChild(4)
If you do this, I recommend null-checking.
See https://docs.unity3d.com/ScriptReference/Transform.GetChild.html
However, I could recommend you to create a variable:
public Transform TargetChild5;
And then assign the value by dragging the 5th child into the slot in your script (in inspector)
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
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.
As title says. How to run SKAction only on parent only (children not affected by it)?
I have some SKSpriteNodes with children, but I would like to manually control which actions are run on each children and that actions are not inherited from parent
SpriteKit does not work this way. If your children should not be affected by the parent's movement, perhaps you should reconsider making them children.
However, there is a fun workaround: run an action on the children that counteracts the parent's movement. For example, if you run an action on the parent that moves to the left, run an action on all the children that moves them to the right simultaneously.