Announcement

Collapse
No announcement yet.

Is this code crappy?

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

    Is this code crappy?

    Hi

    Been busy with a little game and need to destroy and respawn a little spaceship.

    I want a delay before the spaceship is respawned, but if you just put a delay node
    before the SpawnActor it does not work.

    What I have here works fine, but is there a better/more refined way to do it and will
    this way cause problems?

    Click image for larger version

Name:	Screenshot-20180808-12.57.46.png
Views:	16
Size:	473.8 KB
ID:	1512704

    Regards

    Shaun
    https://speed7.artstation.com/

    #2
    You could "SetLifeSpan" instead. When LifeSpan is set it begins ticking down and destroys itself when it reaches 0.

    "Event Destroyed" is then called that you can use to Spawn a new Actor.

    Alternatively you could reset your existing actor and avoid destroying it and instead make sure every variable is reset/initialized again.

    Comment


      #3
      Hi GarnerP57

      Thanks for that!

      Unless I do not understand the function fully, I do not think that I could use LifeSpan as it seems
      to be a fixed time node? The spaceship in the game will get destroyed when the player makes a
      mistake.

      Would you mind expounding on your second point as I have no idea how to do that.

      Regards

      Shaun
      https://speed7.artstation.com/

      Comment


        #4
        An Actor can start with having an infinite LifeSpan (set to 0) and then during Run-Time be set to a LifeSpan other than 0 giving it a finite LifeSpan.

        "Event Destroyed" is the event that is called when the Actor is destroyed just like "Begin Play" is the Event that is called when the Actor is spawned.

        Somewhere in your game you probably have a count of how many space ships you have left. This could be a good place to spawn a new space ship after "Event Destroyed" was called on the old one.

        If you are familiar with Event Dispatchers the space ship spawning Blueprint should bind itself to Event Destroyed when spawning a new space ship so it knows when it was destroyed and can prepare to spawn the next one.

        This way the space ships themselves don't have to spawn the next one but it is instead handled in a persistent Blueprint.

        Comment


          #5
          Hi GarnerP57

          Being extremely new to this it has taken me the whole night to attempt what you suggested.

          It is working great and I am getting the nice 2 second delay before the respawn, I however
          could only get it working on EventTick, when I used EventDestroyed it would only respawn
          once.

          Thanks very much for the help. Hopefully I have executed what you suggested.


          Click image for larger version

Name:	Screenshot-20180809-21.44.22.png
Views:	13
Size:	442.1 KB
ID:	1513436

          Click image for larger version

Name:	Screenshot-20180809-21.48.04.png
Views:	13
Size:	378.9 KB
ID:	1513437

          Regards

          Shaun



          https://speed7.artstation.com/

          Comment


            #6
            Hi again Speed777777

            You nearly got it but don't worry I did not thoroughly explain myself.

            You need to bind to every new SpaceShip you spawn which you can do while spawning it.

            Also note that "OnDestroyed" already exist so you don't need to make a new "Event Dispatcher"

            Click image for larger version

Name:	SpaceShipManager.PNG
Views:	16
Size:	148.1 KB
ID:	1513489
            Doing it your own way is a good learning experience though so enjoy the ride.

            Comment


              #7
              Hi GarnerP57

              THANKS FOR THE HELP!!!

              Flawless now.

              https://youtu.be/v5JGH5fWlWs

              Regards

              Shaun
              https://speed7.artstation.com/

              Comment

              Working...
              X