Good morning everyone.
I have 2 Actor classes called Red and Pink ghosts.
Both use the same MoveGhost feature.
I would like to create a GhostInterface interface where to put this function. and inherit it from the 2 actor classes of the Red and Pink ghosts.
My problem is as follows: in the MoveGhost function there is the following line of code:
Inside GhostInterface.cpp this line of code gives me an error in the word GetWorld (unidentified).
MoveGhost needs to be able to access information from the AMyGameMode class so I need to use the above line of code but it seems that within the interfaces I can’t.
From the symptoms and code snippet I’m guessing you are working on multiplayer game. Game mode exists only on server. If you want access it’s data on client you can either share it through player controller (client’s controller can send a request to server and receive data in response) or store data in class that exists on both client and server like GameState.
Hi,
I will have to make a couple of assumptions in order to attempt to answer your question.
I am assuming that what you want is a common implementation for the two actors and not an interface that allows you to implement different logic for the two actors.
For this purpose you should implement a common class e.g. GhostBase which inherits from actor and inherit you Red and Pink Ghosts from this common class. There are many other options for doing this but I think this will be the easiest one.
Your specific problem is that an interface does not have access to the world, which is why you are getting the compiler error.
In the second code line you are giving I am assuming that this is either the ghost or the interface which are unrelated to the game mode. The Unreal Cast template is a soft cast and will return nullptr when unable to cast.
Good morning,
I solved it with the GhostBase suggestion.
I created a GhostBase where I implemented the 2 functions used by all ghosts (SelectWay and ChangeGhostDirection).
Also in the GhostBase I have added other functions which will then be implemented by the individual ghosts (ControlGhostPosition()).