Can't move instantiated object.
Hey guys,
I've got a instantiated object/prefab and I can't modify it's position.
Here is a code snippet (in a script outside of the prefab):
for (int i = 0; i < protags.Count; i++)
{
protags[i]._sprite = Instantiate(Resources.Load("Demon"),
new Vector3(0, 0, 0),
Quaternion.identity) as GameObject;
}
foreach (Protag ptag in protags)
{
**Vector3 theScale = ptag._sprite.transform.localScale;
theScale.x *= -1;
ptag._sprite.transform.localScale = theScale;**
Vector3 thePos = ptag._sprite.transform.position;
thePos.x = 200;
ptag._sprite.transform.position = thePos;
}
The only modification that seems to work is manipulating the object's scale (in bold). Everything else doesn't yield any results, I've tried many methods such as modifying the position, localPosition, Translate, adding force to it's Rigidbody2D, using a script inside the prefab.
Any advice would be perfect. Thanks.
Hi,
I m assu$$anonymous$$g the basic mistakes here like the script is not attached or not enabled 2) $$anonymous$$ay be object is marked as static (a check box present at top right corner in inspector ) These are two basic issues by which you are not able to move ...
By the way, have you debugged your code by placing logs ??? What is the result for the same
Thanks for the advice, I'll cross check with your answer. Also I forgot to mention I put debugs before and after the position change and it outputted that the position was changed, but not visually with the object.
Checked those two suggestions. I have a separate script that instantiates the object then modifies it. Objects that are already in the scene can be transformed fine, it's just with instantiated objects that it doesn't seem to work.
Answer by rookiemistakes · Jan 27, 2016 at 03:05 AM
Okay found out the solution, it was the Animator component causing issues. I encased the object in a another blank GameObject and edited the Transform of that. Not sure WHY it wouldn't accept my previous modifications, must be a bug.