Jump to content

ObjectReference.SetPosition not working


Recommended Posts

I'm a fairly experienced modder and scripter, but this is baffling me and I can't find any information about similar issues. My script is working flawlessly up to this point so I'm only going to show the snippet I'm having issues with for the sake of brevity. The FormList in the script is loaded with object references of statics I have in my custom cell.

Int i = SOTS_FormList_MoneyPitCoins.GetSize()
Float _CurrentCoinZ = 40.3034

While (i > 0)
	i -= 1
		
	ObjectReference thisPile = SOTS_FormList_MoneyPitCoins.GetAt(i) As ObjectReference
	
        ;I did this as a control test - it does nothing. The statics stay where they are. (No, they are not starting at 0,0,0.)
	thisPile.SetPosition(0.0, 0.0, 0.0)

        ;(Yes, I'm aware the lines below are commented out. I did that to test the line above. I tested each of these one at a time.)
        ;Like the first SetPosition, this does nothing and the statics do not move.)
	;thisPile.SetPosition(thisPile.X, thisPile.Y, thisPile.Z + _CurrentCoinZ) ;This doesn't work for some reason.
	
        ;This does not work as well.
        ;thisPile.MoveTo(thisPile, 0.0, 0.0, _CurrentCoinZ)

        ;This is the only function that works, but it makes the statics indefinitely blurry for some reason and looks really bad.
	;thisPile.TranslateTo(thisPile.X, thisPile.Y, thisPile.Z + _CurrentCoinZ, 0.0, 0.0, thisPile.GetAngleZ(), 50.0)
EndWhile

I also tried disabling each static before calling SetPosition and then re-enabling it again but that did not fix anything. (I saw them each flash when they got disabled and enabled but their positions still did not move.) I know the references are good - Enable, Disable, and TranslateTo all work on them, but I just can't figure out why SetPosition and MoveTo won't work. I really don't care which one I use so long as it works. I'd be fine with using Translate to but (as stated in the script comments) it makes the statics have a weird blur effect indefinitely.
So, yeah, I'm at a loss. Does anyone have any idea what is causing this?

 

(Edit): I found that disabling and then enabling each static after translation gets rid of the blur. I suppose this will be good enough for now but I still can't understand why SetPosition won't work.

Edited by lDelta6l
Link to comment
Share on other sites

I've found for statics using moveto or setposition doesn't work most of the time. Try disabling before moving then enabling after, I've had some luck with that. Alternatively, you could disable / delete the statics and then place new ones with PlaceAtMe at the new position.

 

Also, you could try making them moveable statics. That might work too.

Link to comment
Share on other sites

You cannot place an object to the world without an anchor or the right coordinates. Cells may have totally different x,y,z values, which means (0,0,0) is anywhere else, but not in the visible part of the cell.

 

By using this

thisPile.MoveTo(thisPile, 0.0, 0.0, _CurrentCoinZ)

You have the same issue, because the object is somewhere "Over the rainbow".

code snippet

 

    actor player = Game.GetPlayer()                                    ; an anchor you want to move to
;;; objectReference playerRef = Game.GetPlayer() as ObjectReference    ; or the anchor as object

    float _CurrentCoinZ = 10.3034         ; z variance

    float[] a = new Float[6]              ; array to store current anchor position
    a[0] = player.GetPositionX()          ; fx
    a[1] = player.GetPositionY()          ; fy
    a[2] = player.GetPositionZ() + _CurrentCoinZ
    
    a[3] = player.GetAngleX()             ; aX
    a[4] = player.GetAngleY()             ; aY
    a[5] = player.GetAngleZ()             ; aZ

    int i = SOTS_FormList_MoneyPitCoins.GetSize()
    WHILE (i > 0)
        i = i - 1

        objectReference oRef = SOTS_FormList_MoneyPitCoins.GetAt(i) as ObjectReference
        IF ( oRef )
            ; variant A
            oRef.SetPosition(a[0], a[1], a[2])            ; thisPile.SetPosition(0.0, 0.0, 0.0)
            oRef.SetAngle(a[3], a[4], a[5])

            ; variant B
;;;         oRef.DisableNoWait()
;;;         oRef.MoveTo(player, 0.0, 0.0, _CurrentCoinZ)
;;;         oRef.EnableNoWait()
        ENDIF
    ENDWHILE

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

@AnishaDawn - I had not, but I tried it and it didn't work. Good suggestion, though.

@dybill - I had tried enabling and disabling before (as stated in the initial post) but I tried it again with some Utility.Wait calls just to be safe but it still didn't work. I then tried using Moveable Statics instead and SetPosition worked! Thanks!

@ReDragon2013 - I think you misunderstand the context. World point 0,0,0 is highly visible in my cell (I actually use it as a test point for my more advanced systems). Regardless, when I was trying to move the statics to 0,0,0, I was merely trying to see if they'd move at all (which they did not). After changing the objects to Moveable Statics (as suggested by dybill) moving them to 0,0,0 with SetPosition worked perfectly. Thanks for the response, though!

Link to comment
Share on other sites

SOLUTION(ish):

As suggested by @dybill, using Moveable Statics instead of Statics allowed SetPosition to work.

 

I still don't understand why this script won't work on Statics, especially considering I have other scripts that move statics using SetPosition and they work perfectly. The only difference that I'm aware of is that those other scripts are using different static models and aren't getting their object references from a form list. So... who knows.

Edited by lDelta6l
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...