Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

Placing Static Mesh/Actor into map via UnrealScript?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Placing Static Mesh/Actor into map via UnrealScript?

    Is it possible to spawn a Static Mesh (or any actor, for that matter) into a map using UnrealScript?
    What I am trying to achieve is basically a randomly generated maze map, which consists out of cubic meshes. (If you happen to know the movie CUBE, you may get the idea)

    While the algorithm should not be a real issue to me, I am entirely clueless on how to actually spawn actors, meshes and prefabs using only UnrealScript.
    I have been programming stuff in Java for half a year now and I am fully aware of the concept of OOP and coding in general. However, I am entirely new to Unreal and ultimately UnrealScript.

    Code:
    class CubeActor extends StaticMeshActor 
    	placeable;
    
    DefaultProperties
    {
    	Begin Object Name=StaticMeshComponent0 //Why does it have to be zero?
    		CastShadow=false
    		StaticMesh=StaticMesh'HU_Deco3.SM.Mesh.S_HU_Deco_SM_GasTanks01' //Placeholder
    		bAllowAmbientOcclusion=true
    	End Object
    	
    	bStatic=true
    	bMovable=false
    	CollisionComponent=StaticMeshComponent0
    	bCollideActors=true
    }
    How do I write a method (function) that places an object of this class into a level?
    How do I set the coordinates for this mesh?
    Is it possible to write a method that changes the 'HU_Deco3.SM.Mesh.S_HU_Deco_SM_GasTanks01' into any StaticMesh I'd like, using parameters?

    (I can't find anything helpful in the superclass)


    I am looking forward to any kind of help.
    Thanks.

  • #2
    maybe in your gameinfo class in PostBeginPlay() function

    Spawn(class'CubeActor',,, SomeLocation, SomeRotation);

    changing the static mesh is a bit more tricky because you cant change things in objects that are declared in DefaultProperties.

    Comment


    • #3
      What are the correct parameter data types for the Spawn() function? nFringe fails to deliver this information. According to Visual Studio, this function does not even exist. It's not underlined though.
      Usually Eclipse (hurr, Java) would give me a hint like methodBlabla(int, String, long, byte)

      Comment


      • #4
        It is defined in Actor.uc as:

        Code:
        native noexport final function coerce actor Spawn
        (
        	class<actor>      SpawnClass,
        	optional actor	  SpawnOwner,
        	optional name     SpawnTag,
        	optional vector   SpawnLocation,
        	optional rotator  SpawnRotation,
        	optional Actor    ActorTemplate,
        	optional bool	  bNoCollisionFail
        );

        Comment


        • #5
          Okay, got it so far. However, I still can't get it to work. Whenever I call "cube" from the console, I get the following message:

          "Warning: SpawnActor failed because class CubeActor has bStatic or bNoDelete"

          The problem is: There is no bStatic nor a bNoDelete in my class...


          Code below:

          CubeActor.uc
          Code:
          class CubeActor extends StaticMeshActor 
          	placeable;
          
          DefaultProperties
          {
          	Begin Object Name=StaticMeshComponent0 //Why does it have to be zero?
          		CastShadow=false
          		StaticMesh=StaticMesh'HU_Deco3.SM.Mesh.S_HU_Deco_SM_GasTanks01' //Placeholder
          		bAllowAmbientOcclusion=true
          	End Object
          	
          	//bStatic=true
          	bMovable=false
          	CollisionComponent=StaticMeshComponent0
          	bCollideActors=true
          }
          CubeGameMode.uc:
          Code:
          class CubeGameMode extends UTGame; //Temp extension. I just like to shoot ****
          
          var vector cubeloc;
          
          DefaultProperties
          {
              //PlayerControllerClass=class'CubeGame.PlayerController'
              //DefaultPawnClass=class'CubeGame.Pawn'
              //HUDType=class'CubeGame.HUD'
          }
          
          function exec cube()
          {
          	cubeloc.X = 1;
          	cubeloc.Y = 1;
          	cubeloc.Z = 1;
          	Spawn(class'CubeActor',,,cubeloc,,,);
          }

          Comment


          • #6
            extend Actor instead of StaticMeshActor

            and declare the component like this
            DefaultProperties
            {
            Begin Object class=StaticMeshComponent Name=WhateverYouWant
            .......

            btw try Wotgreal instead of nfringe

            Comment


            • #7
              Setting up WOTGreal was nothing but a frustrating mess.

              I followed your advice. The function cube() is still called, but nothing happens. Not even the Debug log gives me any kind of information, expect the fact that the method was called. (Because I called 'log() at the top)

              Comment


              • #8
                Getting to grips with UnrealScript and learning it's quirks is a bit of a journey. Firstly your DefaultProperties block must come last - you cannot have a function or anything else after it. The class structure order must be:
                • class declaration
                • all global variables
                • methods
                • default properties
                The spawn function may fail if the location will embed it in collision geometry. The final argument to Spawn() is a bool to prevent this.

                The name of 'StaticMeshComponent0' in default properties relates to the object defined in the base class. Essentially you are overriding the properties it defines in that class.

                Comment


                • #9
                  Hahahaha, I did it!

                  All that was missing was:
                  Code:
                  Components.Add(Cube0)
                  Thanks to everyone!

                  Comment


                  • #10
                    I'm in a very similar situation as yourself.
                    I tried copying the code you posted here, but I can't access Components because it's private... I do assume that you didn't change the Actor class though, so I have no idea how you did it.

                    Could you perhaps copy the exact code I need to spawn a block here?


                    If you haven't done the maze algorithm yet, I can share my version with you, although it's done in C#-Script and still needs to be ported to UnrealScript.

                    Comment


                    • #11
                      Well, I managed to figure it out on my own.
                      I posted the code on my blog in case anyone runs into similar problems in the future:
                      http://maze.not-a-number.net/?p=19

                      Comment


                      • #12
                        LOL, it doesnt have to be zero im guessing its just like that because the zero stops the autocompletion from turning it into something you dont want.

                        Comment

                        Working...
                        X